Quote:
|
Originally Posted by foebea
...I need to find out how you do your unicode so I can add that support to my own program :D...
|
Ok, there is two functions for working with Utf-8-strings:
Code:
int GetUTF8CharLenght(char *str)
{
if (!(*str & 0x80))
{
return 1;
}
else if ((*str&0xE0) == 0xC0 && (*(str+1)&0xC0) == 0x80)
{
return 2;
}
else if ((*str&0xF0) == 0xE0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80)
{
return 3;
}
else if ((*str&0xF8) == 0xF0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80 && (*(str+3)&0xC0) == 0x80)
{
return 4;
}
return 1;
}
unsigned int GetCharFromUTF8(char *&str)
{
unsigned int ch;
if (!(*str & 0x80))
{
ch = *str;
str++;
}
else if ((*str&0xE0) == 0xC0 && (*(str+1)&0xC0) == 0x80)
{
ch = (*str&0x1F)<<6 | *(str+1)&0x3F;
str += 2;
}
else if ((*str&0xF0) == 0xE0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80)
{
ch = (*str&0x0F)<<12 | (*(str+1)&0x3F)<<6 | *(str+2)&0x3F;
str += 3;
}
else if ((*str&0xF8) == 0xF0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80 && (*(str+3)&0xC0) == 0x80)
{
ch = (*str&0x07)<<18 | (*(str+1)&0x3F)<<12 | (*(str+2)&0x3F)<<6 | *(str+3)&0x3F;
str += 4;
}
else
{
ch = '?';
str++;
}
return ch;
}