mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-29 15:34:07 +02:00
trunk/branch integration: fixbug
This commit is contained in:
parent
89fd4a231a
commit
a967b0fb9e
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// UnicodeConverter.cpp
|
// UnicodeConverter.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/UnicodeConverter.cpp#2 $
|
// $Id: //poco/1.4/Foundation/src/UnicodeConverter.cpp#1 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Text
|
// Package: Text
|
||||||
@ -55,7 +55,20 @@ void UnicodeConverter::toUTF16(const std::string& utf8String, std::wstring& utf1
|
|||||||
UTF8Encoding utf8Encoding;
|
UTF8Encoding utf8Encoding;
|
||||||
TextIterator it(utf8String, utf8Encoding);
|
TextIterator it(utf8String, utf8Encoding);
|
||||||
TextIterator end(utf8String);
|
TextIterator end(utf8String);
|
||||||
while (it != end) utf16String += (wchar_t) *it++;
|
while (it != end)
|
||||||
|
{
|
||||||
|
int cc = *it++;
|
||||||
|
if (cc <= 0xffff)
|
||||||
|
{
|
||||||
|
utf16String += (wchar_t) cc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cc -= 0x10000;
|
||||||
|
utf16String += (wchar_t) ((cc >> 10) & 0x3ff) | 0xd800;
|
||||||
|
utf16String += (wchar_t) (cc & 0x3ff) | 0xdc00;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,28 +85,44 @@ void UnicodeConverter::toUTF16(const char* utf8String, int length, std::wstring&
|
|||||||
|
|
||||||
while (it < end)
|
while (it < end)
|
||||||
{
|
{
|
||||||
unsigned char c = *it;
|
int n = utf8Encoding.queryConvert(it, 1);
|
||||||
int n = utf8Encoding.characterMap()[c];
|
int uc;
|
||||||
int uc = '?';
|
int read = 1;
|
||||||
if (n == -1)
|
|
||||||
|
while (-1 > n && (end - it) >= -n)
|
||||||
{
|
{
|
||||||
++it;
|
read = -n;
|
||||||
|
n = utf8Encoding.queryConvert(it, read);
|
||||||
}
|
}
|
||||||
else if (n >= 0)
|
|
||||||
|
if (-1 > n)
|
||||||
{
|
{
|
||||||
uc = n;
|
it = end;
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (it - n <= end)
|
it += read;
|
||||||
{
|
}
|
||||||
uc = utf8Encoding.convert(it);
|
|
||||||
if (uc == -1) uc = '?';
|
if (-1 >= n)
|
||||||
}
|
{
|
||||||
it -= n;
|
uc = 0xfffd; // Replacement Character (instead of '?')
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uc = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uc > 0xffff)
|
||||||
|
{
|
||||||
|
uc -= 0x10000;
|
||||||
|
utf16String += (wchar_t) ((uc >> 10) & 0x3ff) | 0xd800 ;
|
||||||
|
utf16String += (wchar_t) (uc & 0x3ff) | 0xdc00 ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
utf16String += (wchar_t) uc;
|
||||||
}
|
}
|
||||||
utf16String += (wchar_t) uc; // TODO: surrogates
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user