Commit 022eed1a authored by salix5's avatar salix5

DecodeUTF8()

parent 1f987b40
...@@ -60,6 +60,7 @@ public: ...@@ -60,6 +60,7 @@ public:
*pstr = 0; *pstr = 0;
return l; return l;
} }
// UCS-2 to UTF-8
static int EncodeUTF8(const wchar_t * wsrc, char * str) { static int EncodeUTF8(const wchar_t * wsrc, char * str) {
char* pstr = str; char* pstr = str;
while(*wsrc != 0) { while(*wsrc != 0) {
...@@ -81,6 +82,7 @@ public: ...@@ -81,6 +82,7 @@ public:
*str = 0; *str = 0;
return str - pstr; return str - pstr;
} }
// UTF-8 to UCS-2
static int DecodeUTF8(const char * src, wchar_t * wstr) { static int DecodeUTF8(const char * src, wchar_t * wstr) {
const char* p = src; const char* p = src;
wchar_t* wp = wstr; wchar_t* wp = wstr;
...@@ -89,13 +91,13 @@ public: ...@@ -89,13 +91,13 @@ public:
*wp = *p; *wp = *p;
p++; p++;
} else if((*p & 0xe0) == 0xc0) { } else if((*p & 0xe0) == 0xc0) {
*wp = (((int)p[0] & 0x1f) << 6) | ((int)p[1] & 0x3f); *wp = (((unsigned)p[0] & 0x1f) << 6) | ((unsigned)p[1] & 0x3f);
p += 2; p += 2;
} else if((*p & 0xf0) == 0xe0) { } else if((*p & 0xf0) == 0xe0) {
*wp = (((int)p[0] & 0xf) << 12) | (((int)p[1] & 0x3f) << 6) | ((int)p[2] & 0x3f); *wp = (((unsigned)p[0] & 0xf) << 12) | (((unsigned)p[1] & 0x3f) << 6) | ((unsigned)p[2] & 0x3f);
p += 3; p += 3;
} else if((*p & 0xf8) == 0xf0) { } else if((*p & 0xf8) == 0xf0) {
*wp = (((int)p[0] & 0x7) << 18) | (((int)p[1] & 0x3f) << 12) | (((int)p[2] & 0x3f) << 6) | ((int)p[3] & 0x3f); *wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
p += 4; p += 4;
} else } else
p++; p++;
......
Subproject commit 35927886a1effa6c8a2eccaa1eff2eb84e8595b3 Subproject commit 95bc5de881cc3b0b6108b0236ecce197a40af5b3
Subproject commit 9da642fec10fcc0cf90041d5ded55db02a4b619c Subproject commit eda89570a613c7ba4e7e23a36b2c66a8420cbc61
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment