add LcharToUTF8
This commit is contained in:
@@ -917,3 +917,48 @@ lstring CStringToLstring(const CString &str)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int unichar_to_utf8 (longchar c, char *outbuf)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
int first;
|
||||
|
||||
if (c < 0x80) {
|
||||
first = 0;
|
||||
len = 1;
|
||||
} else if (c < 0x800) {
|
||||
first = 0xc0;
|
||||
len = 2;
|
||||
} else if (c < 0x10000) {
|
||||
first = 0xe0;
|
||||
len = 3;
|
||||
} else if (c < 0x200000) {
|
||||
first = 0xf0;
|
||||
len = 4;
|
||||
} else if (c < 0x4000000) {
|
||||
first = 0xf8;
|
||||
len = 5;
|
||||
} else {
|
||||
first = 0xfc;
|
||||
len = 6;
|
||||
}
|
||||
|
||||
if (outbuf)
|
||||
{
|
||||
for (int i = len - 1; i > 0; --i)
|
||||
{
|
||||
outbuf[i] = char((c & 0x3f) | 0x80);
|
||||
c >>= 6;
|
||||
}
|
||||
outbuf[0] = char(c | first);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
CString LcharToUTF8( longchar c )
|
||||
{
|
||||
char buf[6];
|
||||
int cnt = unichar_to_utf8(c, buf);
|
||||
return CString(buf, cnt);
|
||||
}
|
||||
|
||||
@@ -154,6 +154,7 @@ typedef int longchar;
|
||||
typedef basic_string<longchar> lstring;
|
||||
|
||||
lstring CStringToLstring(const CString &str);
|
||||
CString LcharToUTF8( longchar c );
|
||||
|
||||
// Splits a CString into an CStringArray according the Deliminator.
|
||||
void split(
|
||||
|
||||
Reference in New Issue
Block a user