wxChar to utf8 char Topic is solved
wxChar to utf8 char
Please help, how to convert wxChar to character in UTF8( int )?
Solution for me:
Code: Select all
/**********************************************************************************************/
int UtfToUniChar( char *str, int* chPtr )
{
int byte = *((unsigned char *) str);
if( byte < 0xC0 )
{
*chPtr = (int) byte;
return 1;
}
else if( byte < 0xE0 )
{
if( ( str[ 1 ] & 0xC0 ) == 0x80 )
{
*chPtr = (int) (((byte & 0x1F) << 6) | (str[1] & 0x3F));
return 2;
}
*chPtr = (int) byte;
return 1;
}
else if( byte < 0xF0 )
{
if( ( ( str[ 1 ] & 0xC0 ) == 0x80 ) && ( ( str[ 2 ] & 0xC0 ) == 0x80 ) )
{
*chPtr = (int) ( ( ( byte & 0x0F ) << 12 ) |
( ( str[ 1 ] & 0x3F ) << 6 ) | ( str[ 2 ] & 0x3F ) );
return 3;
}
*chPtr = (int) byte;
return 1;
}
*chPtr = (int) byte;
return 1;
}
...
char ustring[ 32768 ];
strcpy( ustring, (const char*) text.mb_str( wxConvUTF8 ) );
char* next = ustring;
for( int i = 0 ; *next ; ++i )
{
int ch = 0;
int len = UtfToUniChar( next, &ch );
next += len;
}
...