mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 10:37:41 -04:00
Clean up some useless junk from plString
This commit is contained in:
@ -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,53 +366,8 @@ plStringBuffer<wchar_t> plString::ToWchar() const
|
||||
plStringBuffer<uint16_t> utf16 = ToUtf16();
|
||||
return *reinterpret_cast<plStringBuffer<wchar_t>*>(&utf16);
|
||||
#else
|
||||
plStringBuffer<wchar_t> result;
|
||||
if (IsEmpty())
|
||||
return result;
|
||||
|
||||
// Calculate the UCS-4 size
|
||||
size_t convlen = 0;
|
||||
const char *utf8 = fUtf8Buffer.GetData();
|
||||
const char *sp = utf8;
|
||||
size_t srcSize = fUtf8Buffer.GetSize();
|
||||
while (sp < utf8 + srcSize) {
|
||||
if ((*sp & 0xF8) == 0xF0)
|
||||
sp += 4;
|
||||
else if ((*sp & 0xF0) == 0xE0)
|
||||
sp += 3;
|
||||
else if ((*sp & 0xE0) == 0xC0)
|
||||
sp += 2;
|
||||
else
|
||||
sp += 1;
|
||||
++convlen;
|
||||
}
|
||||
|
||||
// And perform the actual conversion
|
||||
wchar_t *wstr = result.CreateWritableBuffer(convlen);
|
||||
wchar_t *dp = wstr;
|
||||
sp = utf8;
|
||||
while (sp < utf8 + srcSize) {
|
||||
unsigned int unichar;
|
||||
if ((*sp & 0xF8) == 0xF0) {
|
||||
unichar = (*sp++ & 0x07) << 18;
|
||||
unichar |= (*sp++ & 0x3F) << 12;
|
||||
unichar |= (*sp++ & 0x3F) << 6;
|
||||
unichar |= (*sp++ & 0x3F);
|
||||
} else if ((*sp & 0xF0) == 0xE0) {
|
||||
unichar = (*sp++ & 0x0F) << 12;
|
||||
unichar |= (*sp++ & 0x3F) << 6;
|
||||
unichar |= (*sp++ & 0x3F);
|
||||
} else if ((*sp & 0xE0) == 0xC0) {
|
||||
unichar = (*sp++ & 0x1F) << 6;
|
||||
unichar |= (*sp++ & 0x3F);
|
||||
} else {
|
||||
unichar = *sp++;
|
||||
}
|
||||
*dp++ = unichar;
|
||||
}
|
||||
wstr[convlen] = 0;
|
||||
|
||||
return result;
|
||||
plUnicodeBuffer utf32 = GetUnicodeArray();
|
||||
return *reinterpret_cast<plStringBuffer<wchar_t>*)(&utf32);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -444,7 +399,7 @@ plStringBuffer<char> plString::ToIso8859_1() const
|
||||
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;
|
||||
@ -473,12 +428,46 @@ plUnicodeBuffer plString::GetUnicodeArray() const
|
||||
if (IsEmpty())
|
||||
return result;
|
||||
|
||||
size_t convlen = GetUniCharCount();
|
||||
// Calculate the UCS-4 size
|
||||
size_t convlen = 0;
|
||||
const char *utf8 = fUtf8Buffer.GetData();
|
||||
const char *sp = utf8;
|
||||
size_t srcSize = fUtf8Buffer.GetSize();
|
||||
while (sp < utf8 + srcSize) {
|
||||
if ((*sp & 0xF8) == 0xF0)
|
||||
sp += 4;
|
||||
else if ((*sp & 0xF0) == 0xE0)
|
||||
sp += 3;
|
||||
else if ((*sp & 0xE0) == 0xC0)
|
||||
sp += 2;
|
||||
else
|
||||
sp += 1;
|
||||
++convlen;
|
||||
}
|
||||
|
||||
// And perform the actual conversion
|
||||
UniChar *ustr = result.CreateWritableBuffer(convlen);
|
||||
iterator iter = GetIterator();
|
||||
size_t dp = 0;
|
||||
while (!iter.AtEnd())
|
||||
ustr[dp++] = *iter++;
|
||||
UniChar *dp = ustr;
|
||||
sp = utf8;
|
||||
while (sp < utf8 + srcSize) {
|
||||
UniChar unichar;
|
||||
if ((*sp & 0xF8) == 0xF0) {
|
||||
unichar = (*sp++ & 0x07) << 18;
|
||||
unichar |= (*sp++ & 0x3F) << 12;
|
||||
unichar |= (*sp++ & 0x3F) << 6;
|
||||
unichar |= (*sp++ & 0x3F);
|
||||
} else if ((*sp & 0xF0) == 0xE0) {
|
||||
unichar = (*sp++ & 0x0F) << 12;
|
||||
unichar |= (*sp++ & 0x3F) << 6;
|
||||
unichar |= (*sp++ & 0x3F);
|
||||
} else if ((*sp & 0xE0) == 0xC0) {
|
||||
unichar = (*sp++ & 0x1F) << 6;
|
||||
unichar |= (*sp++ & 0x3F);
|
||||
} else {
|
||||
unichar = *sp++;
|
||||
}
|
||||
*dp++ = unichar;
|
||||
}
|
||||
ustr[convlen] = 0;
|
||||
|
||||
return result;
|
||||
|
@ -324,115 +324,6 @@ public:
|
||||
{ return _L.Compare(_R, kCaseInsensitive) == 0; }
|
||||
};
|
||||
|
||||
public:
|
||||
struct iterator
|
||||
{
|
||||
iterator() : m_ptr(nil), m_end(nil) { }
|
||||
iterator(const iterator ©) : m_ptr(copy.m_ptr), m_end(copy.m_end) { }
|
||||
|
||||
iterator &operator=(const iterator ©)
|
||||
{ m_ptr = copy.m_ptr; m_end = copy.m_end; return *this; }
|
||||
|
||||
iterator &operator++()
|
||||
{
|
||||
if ((*m_ptr & 0xF8) == 0xF0)
|
||||
m_ptr += 4;
|
||||
else if ((*m_ptr & 0xF0) == 0xE0)
|
||||
m_ptr += 3;
|
||||
else if ((*m_ptr & 0xE0) == 0xC0)
|
||||
m_ptr += 2;
|
||||
else
|
||||
m_ptr += 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator++(int)
|
||||
{
|
||||
iterator iter_save = *this;
|
||||
(void) operator++();
|
||||
return iter_save;
|
||||
}
|
||||
|
||||
iterator &operator+=(size_t delta)
|
||||
{
|
||||
while (delta) {
|
||||
operator++();
|
||||
--delta;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator+(size_t delta) const
|
||||
{
|
||||
iterator copy(*this);
|
||||
copy += delta;
|
||||
return copy;
|
||||
}
|
||||
|
||||
int operator-(const iterator &other) const
|
||||
{
|
||||
return (int)(m_ptr - other.m_ptr);
|
||||
}
|
||||
|
||||
bool operator==(const iterator &other) const { return m_ptr == other.m_ptr; }
|
||||
bool operator!=(const iterator &other) const { return m_ptr != other.m_ptr; }
|
||||
bool operator<(const iterator &other) const { return m_ptr < other.m_ptr; }
|
||||
bool operator>(const iterator &other) const { return m_ptr > other.m_ptr; }
|
||||
bool operator<=(const iterator &other) const { return m_ptr <= other.m_ptr; }
|
||||
bool operator>=(const iterator &other) const { return m_ptr >= other.m_ptr; }
|
||||
|
||||
UniChar operator*() const
|
||||
{
|
||||
UniChar ch;
|
||||
if ((*m_ptr & 0xF8) == 0xF0) {
|
||||
ch = (m_ptr[0] & 0x07) << 18;
|
||||
ch |= (m_ptr[1] & 0x3F) << 12;
|
||||
ch |= (m_ptr[2] & 0x3F) << 6;
|
||||
ch |= (m_ptr[3] & 0x3F);
|
||||
} else if ((*m_ptr & 0xF0) == 0xE0) {
|
||||
ch = (m_ptr[0] & 0x0F) << 12;
|
||||
ch |= (m_ptr[1] & 0x3F) << 6;
|
||||
ch |= (m_ptr[2] & 0x3F);
|
||||
} else if ((*m_ptr & 0xE0) == 0xC0) {
|
||||
ch = (m_ptr[0] & 0x1F) << 6;
|
||||
ch |= (m_ptr[1] & 0x3F);
|
||||
} else {
|
||||
ch = m_ptr[0];
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
UniChar operator[](size_t offset) const
|
||||
{
|
||||
iterator copy(*this);
|
||||
copy += offset;
|
||||
return *copy;
|
||||
}
|
||||
|
||||
bool AtEnd() const { return m_ptr >= m_end; }
|
||||
bool IsValid() const { return m_ptr != 0; }
|
||||
|
||||
private:
|
||||
friend class plString;
|
||||
iterator(const char *ptr, size_t size) : m_ptr(ptr), m_end(ptr + size) { }
|
||||
|
||||
const char *m_ptr;
|
||||
const char *m_end;
|
||||
};
|
||||
|
||||
iterator GetIterator() const { return iterator(c_str(), GetSize()); }
|
||||
|
||||
size_t GetUniCharCount() const
|
||||
{
|
||||
iterator iter = GetIterator();
|
||||
size_t count = 0;
|
||||
while (!iter.AtEnd()) {
|
||||
++iter;
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
friend plString operator+(const plString &left, const plString &right);
|
||||
friend plString operator+(const plString &left, const char *right);
|
||||
|
Reference in New Issue
Block a user