From 02eebfa9a1719c5bc1dce4919625c5cc16caff66 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Mon, 31 Dec 2012 17:13:12 -0800 Subject: [PATCH] Clean up some useless junk from plString --- Sources/Plasma/CoreLib/plString.cpp | 57 ++++++--------- Sources/Plasma/CoreLib/plString.h | 109 ---------------------------- 2 files changed, 23 insertions(+), 143 deletions(-) diff --git a/Sources/Plasma/CoreLib/plString.cpp b/Sources/Plasma/CoreLib/plString.cpp index 398d5073..606eb2bc 100644 --- a/Sources/Plasma/CoreLib/plString.cpp +++ b/Sources/Plasma/CoreLib/plString.cpp @@ -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 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 plString::ToWchar() const plStringBuffer utf16 = ToUtf16(); return *reinterpret_cast*>(&utf16); #else - plStringBuffer result; + plUnicodeBuffer utf32 = GetUnicodeArray(); + return *reinterpret_cast*)(&utf32); +#endif +} + +plStringBuffer plString::ToIso8859_1() const +{ + plStringBuffer 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 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 plString::ToWchar() const } else { unichar = *sp++; } - *dp++ = unichar; + *dp++ = (unichar < 0xFF) ? unichar : '?'; } - wstr[convlen] = 0; + astr[convlen] = 0; return result; -#endif } -plStringBuffer plString::ToIso8859_1() const +plUnicodeBuffer plString::GetUnicodeArray() const { - plStringBuffer 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 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 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; diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index 76a45087..0553e8ca 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -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);