|
|
@ -163,7 +163,7 @@ void plString::IConvertFromUtf16(const uint16_t *utf16, size_t size) |
|
|
|
while (sp < utf16 + size) { |
|
|
|
while (sp < utf16 + size) { |
|
|
|
if (*sp >= 0xD800 && *sp <= 0xDFFF) { |
|
|
|
if (*sp >= 0xD800 && *sp <= 0xDFFF) { |
|
|
|
// Surrogate pair
|
|
|
|
// Surrogate pair
|
|
|
|
unsigned int unichar = 0x10000; |
|
|
|
UniChar unichar = 0x10000; |
|
|
|
|
|
|
|
|
|
|
|
if (sp + 1 >= utf16 + size) { |
|
|
|
if (sp + 1 >= utf16 + size) { |
|
|
|
hsAssert(0, "Incomplete surrogate pair in UTF-16 data"); |
|
|
|
hsAssert(0, "Incomplete surrogate pair in UTF-16 data"); |
|
|
@ -332,7 +332,7 @@ plStringBuffer<uint16_t> plString::ToUtf16() const |
|
|
|
uint16_t *dp = ustr; |
|
|
|
uint16_t *dp = ustr; |
|
|
|
sp = utf8; |
|
|
|
sp = utf8; |
|
|
|
while (sp < utf8 + srcSize) { |
|
|
|
while (sp < utf8 + srcSize) { |
|
|
|
unsigned int unichar; |
|
|
|
UniChar unichar; |
|
|
|
if ((*sp & 0xF8) == 0xF0) { |
|
|
|
if ((*sp & 0xF8) == 0xF0) { |
|
|
|
unichar = (*sp++ & 0x07) << 18; |
|
|
|
unichar = (*sp++ & 0x07) << 18; |
|
|
|
unichar |= (*sp++ & 0x3F) << 12; |
|
|
|
unichar |= (*sp++ & 0x3F) << 12; |
|
|
@ -366,11 +366,18 @@ plStringBuffer<wchar_t> plString::ToWchar() const |
|
|
|
plStringBuffer<uint16_t> utf16 = ToUtf16(); |
|
|
|
plStringBuffer<uint16_t> utf16 = ToUtf16(); |
|
|
|
return *reinterpret_cast<plStringBuffer<wchar_t>*>(&utf16); |
|
|
|
return *reinterpret_cast<plStringBuffer<wchar_t>*>(&utf16); |
|
|
|
#else |
|
|
|
#else |
|
|
|
plStringBuffer<wchar_t> result; |
|
|
|
plUnicodeBuffer utf32 = GetUnicodeArray(); |
|
|
|
|
|
|
|
return *reinterpret_cast<plStringBuffer<wchar_t>*)(&utf32); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plStringBuffer<char> plString::ToIso8859_1() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
plStringBuffer<char> result; |
|
|
|
if (IsEmpty()) |
|
|
|
if (IsEmpty()) |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
// Calculate the UCS-4 size
|
|
|
|
// Calculate the ASCII size
|
|
|
|
size_t convlen = 0; |
|
|
|
size_t convlen = 0; |
|
|
|
const char *utf8 = fUtf8Buffer.GetData(); |
|
|
|
const char *utf8 = fUtf8Buffer.GetData(); |
|
|
|
const char *sp = utf8; |
|
|
|
const char *sp = utf8; |
|
|
@ -388,11 +395,11 @@ plStringBuffer<wchar_t> plString::ToWchar() const |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// And perform the actual conversion
|
|
|
|
// And perform the actual conversion
|
|
|
|
wchar_t *wstr = result.CreateWritableBuffer(convlen); |
|
|
|
char *astr = result.CreateWritableBuffer(convlen); |
|
|
|
wchar_t *dp = wstr; |
|
|
|
char *dp = astr; |
|
|
|
sp = utf8; |
|
|
|
sp = utf8; |
|
|
|
while (sp < utf8 + srcSize) { |
|
|
|
while (sp < utf8 + srcSize) { |
|
|
|
unsigned int unichar; |
|
|
|
UniChar unichar; |
|
|
|
if ((*sp & 0xF8) == 0xF0) { |
|
|
|
if ((*sp & 0xF8) == 0xF0) { |
|
|
|
unichar = (*sp++ & 0x07) << 18; |
|
|
|
unichar = (*sp++ & 0x07) << 18; |
|
|
|
unichar |= (*sp++ & 0x3F) << 12; |
|
|
|
unichar |= (*sp++ & 0x3F) << 12; |
|
|
@ -408,21 +415,20 @@ plStringBuffer<wchar_t> plString::ToWchar() const |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
unichar = *sp++; |
|
|
|
unichar = *sp++; |
|
|
|
} |
|
|
|
} |
|
|
|
*dp++ = unichar; |
|
|
|
*dp++ = (unichar < 0xFF) ? unichar : '?'; |
|
|
|
} |
|
|
|
} |
|
|
|
wstr[convlen] = 0; |
|
|
|
astr[convlen] = 0; |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
plStringBuffer<char> plString::ToIso8859_1() const |
|
|
|
plUnicodeBuffer plString::GetUnicodeArray() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
plStringBuffer<char> result; |
|
|
|
plUnicodeBuffer result; |
|
|
|
if (IsEmpty()) |
|
|
|
if (IsEmpty()) |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
// Calculate the ASCII size
|
|
|
|
// Calculate the UCS-4 size
|
|
|
|
size_t convlen = 0; |
|
|
|
size_t convlen = 0; |
|
|
|
const char *utf8 = fUtf8Buffer.GetData(); |
|
|
|
const char *utf8 = fUtf8Buffer.GetData(); |
|
|
|
const char *sp = utf8; |
|
|
|
const char *sp = utf8; |
|
|
@ -440,11 +446,11 @@ plStringBuffer<char> plString::ToIso8859_1() const |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// And perform the actual conversion
|
|
|
|
// And perform the actual conversion
|
|
|
|
char *astr = result.CreateWritableBuffer(convlen); |
|
|
|
UniChar *ustr = result.CreateWritableBuffer(convlen); |
|
|
|
char *dp = astr; |
|
|
|
UniChar *dp = ustr; |
|
|
|
sp = utf8; |
|
|
|
sp = utf8; |
|
|
|
while (sp < utf8 + srcSize) { |
|
|
|
while (sp < utf8 + srcSize) { |
|
|
|
unsigned int unichar; |
|
|
|
UniChar unichar; |
|
|
|
if ((*sp & 0xF8) == 0xF0) { |
|
|
|
if ((*sp & 0xF8) == 0xF0) { |
|
|
|
unichar = (*sp++ & 0x07) << 18; |
|
|
|
unichar = (*sp++ & 0x07) << 18; |
|
|
|
unichar |= (*sp++ & 0x3F) << 12; |
|
|
|
unichar |= (*sp++ & 0x3F) << 12; |
|
|
@ -460,25 +466,8 @@ plStringBuffer<char> plString::ToIso8859_1() const |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
unichar = *sp++; |
|
|
|
unichar = *sp++; |
|
|
|
} |
|
|
|
} |
|
|
|
*dp++ = (unichar < 0xFF) ? unichar : '?'; |
|
|
|
*dp++ = unichar; |
|
|
|
} |
|
|
|
|
|
|
|
astr[convlen] = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
plUnicodeBuffer plString::GetUnicodeArray() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
plUnicodeBuffer result; |
|
|
|
|
|
|
|
if (IsEmpty()) |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t convlen = GetUniCharCount(); |
|
|
|
|
|
|
|
UniChar *ustr = result.CreateWritableBuffer(convlen); |
|
|
|
|
|
|
|
iterator iter = GetIterator(); |
|
|
|
|
|
|
|
size_t dp = 0; |
|
|
|
|
|
|
|
while (!iter.AtEnd()) |
|
|
|
|
|
|
|
ustr[dp++] = *iter++; |
|
|
|
|
|
|
|
ustr[convlen] = 0; |
|
|
|
ustr[convlen] = 0; |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|