Advertisement

script string and utf-8

Started by January 07, 2015 09:42 PM
0 comments, last by WitchLord 9 years, 10 months ago

If I'm using the provided script string (add on) and I have a string instance (in script) which is has international glyphs (via utf-8).. is there any existing unicode-aware way to get the logical length()? I'm looking for the number of logical glyphs, not the length of the underlying string, per se.

Thanks.

UTF8 is actually quite friendly in this way. Each byte that doesn't have the bits 8 and 7 set to 0b10 is a new glyph.

int countUTF8Glyphs(const string &str)
{
   int count = 0;
   for( int n = 0; n < str.length(); n++ )
   {
      if( (str[n] & 0xC0) != 0x80 )
        count++;
   }
   return count;
}

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement