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