View Single Post
 
Old 05-22-2007, 10:54 AM
Cy-4AH Cy-4AH is offline
PSP Newbie
 
Join Date: May 2007
Location: Belarus
Posts: 16
Cy-4AH User Has a Beginner Reputation
Default

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;    
}
__________________
Sloynik Release Thread: http://www.psp-hacks.com/forums/viewtopic.php?id=88653
Reply With Quote