 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
kirrukirru
Joined: 06 Oct 2008 Posts: 2
|
Posted: Sat Mar 07, 2009 2:10 am Post subject: Unicode conversion |
|
|
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 |
|
| Back to top |
|
 |
BenHur
Joined: 20 Oct 2007 Posts: 30
|
Posted: Sat Mar 07, 2009 7:52 am Post subject: Re: Unicode conversion |
|
|
| 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. |
UTF-8 to unicode conversion is simple (from libccc which is used by intraFont): | Code: | 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;
} | The library also supports common codepages (Big5,...)
Cheers, BenHur |
|
| Back to top |
|
 |
kirrukirru
Joined: 06 Oct 2008 Posts: 2
|
Posted: Sat Mar 07, 2009 3:25 pm Post subject: |
|
|
Thanks a lot BehHur!!
The code given by you is working fine!! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|