Hi,
I read the Game Title from PARAM.SFO, which is in UTF-8. I need to convert it into Unicode. Please note that I deal with multi-byte characters in game title (Chinese/Japanese etc.) Please help me what are the library functions available to do this conversion.
I tried mbstowcs with setlocale(LC_ALL, "UTF-8"), but doesn't work. I tried to use iconv, but I can't find the necessary lib file in my build environment (with PSPToolchain).
Thanks,
Kiran
Unicode conversion
Re: Unicode conversion
UTF-8 to unicode conversion is simple (from libccc which is used by intraFont):kirrukirru wrote:I read the Game Title from PARAM.SFO, which is in UTF-8. I need to convert it into Unicode. Please note that I deal with multi-byte characters in game title (Chinese/Japanese etc.) Please help me what are the library functions available to do this conversion.
Code: Select all
int cccUTF8toUCS2(cccUCS2 * dst, size_t count, cccCode const * str) {
if (!str || *str == '\0' || !dst) return 0;
int i = 0, length = 0;
while (str[i] && length < count) {
if (str[i] <= 0x7FU) { //ASCII
dst[length] = (cccUCS2)str[i];
i++; length++;
} else if (str[i] <= 0xC1U) { //part of multi-byte or overlong encoding ->ignore
i++;
} else if (str[i] <= 0xDFU) { //2-byte
dst[length] = ((str[i]&0x001fu)<<6) | (str[i+1]&0x003fu);
i += 2; length++;
} else if (str[i] <= 0xEFU) { //3-byte
dst[length] = ((str[i]&0x001fu)<<12) | ((str[i+1]&0x003fu)<<6) | (str[i+2]&0x003fu);
i += 3; length++;
} else i++; //4-byte, restricted or invalid range ->ignore
}
return length;
}
Cheers, BenHur
-
- Posts: 2
- Joined: Mon Oct 06, 2008 2:23 am