diff options
Diffstat (limited to 'source/core/slang-string.cpp')
| -rw-r--r-- | source/core/slang-string.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index 0a5b7d260..e21333809 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -11,15 +11,6 @@ namespace Slang // for anything that uses core static const auto s_charUtilLink = CharUtil::_ensureLink(); - // TODO: this belongs in a different file: - - SLANG_RETURN_NEVER void signalUnexpectedError(char const* message) - { - // Can be useful to uncomment during debug when problem is on CI - // printf("Unexpected: %s\n", message); - throw InternalError(message); - } - // OSString OSString::OSString() @@ -120,6 +111,14 @@ namespace Slang return UnownedStringSlice(start, end); } + UnownedStringSlice UnownedStringSlice::trimStart() const + { + const char* start = m_begin; + + while (start < m_end && CharUtil::isHorizontalWhitespace(*start)) start++; + return UnownedStringSlice(start, m_end); + } + UnownedStringSlice UnownedStringSlice::trim(char c) const { const char* start = m_begin; @@ -217,37 +216,42 @@ namespace Slang String String::fromWString(const wchar_t * wstr) { + List<char> buf; #ifdef _WIN32 - return Slang::Encoding::UTF16->ToString((const char*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t))); + Slang::CharEncoding::UTF16->decode((const Byte*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t)), buf); #else - return Slang::Encoding::UTF32->ToString((const char*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t))); + Slang::CharEncoding::UTF32->decode((const Byte*)wstr, (int)(wcslen(wstr) * sizeof(wchar_t)), buf); #endif + return String(buf.begin(), buf.end()); } String String::fromWString(const wchar_t * wstr, const wchar_t * wend) { + List<char> buf; #ifdef _WIN32 - return Slang::Encoding::UTF16->ToString((const char*)wstr, (int)((wend - wstr) * sizeof(wchar_t))); + Slang::CharEncoding::UTF16->decode((const Byte*)wstr, (int)((wend - wstr) * sizeof(wchar_t)), buf); #else - return Slang::Encoding::UTF32->ToString((const char*)wstr, (int)((wend - wstr) * sizeof(wchar_t))); + Slang::CharEncoding::UTF32->decode((const Byte*)wstr, (int)((wend - wstr) * sizeof(wchar_t)), buf); #endif + return String(buf.begin(), buf.end()); } String String::fromWChar(const wchar_t ch) { + List<char> buf; #ifdef _WIN32 - return Slang::Encoding::UTF16->ToString((const char*)&ch, (int)(sizeof(wchar_t))); + Slang::CharEncoding::UTF16->decode((const Byte*)&ch, (int)(sizeof(wchar_t)), buf); #else - return Slang::Encoding::UTF32->ToString((const char*)&ch, (int)(sizeof(wchar_t))); + Slang::CharEncoding::UTF32->decode((const Byte*)&ch, (int)(sizeof(wchar_t)), buf); #endif + return String(buf.begin(), buf.end()); } - String String::fromUnicodePoint(unsigned int codePoint) + /* static */String String::fromUnicodePoint(Char32 codePoint) { char buf[6]; - int len = Slang::EncodeUnicodePointToUTF8(buf, (int)codePoint); - buf[len] = 0; - return String(buf); + int len = Slang::encodeUnicodePointToUTF8(codePoint, buf); + return String(buf, buf + len); } OSString String::toWString(Index* outLength) const @@ -258,15 +262,15 @@ namespace Slang } else { - List<char> buf; + List<Byte> buf; switch(sizeof(wchar_t)) { case 2: - Slang::Encoding::UTF16->GetBytes(buf, *this); + Slang::CharEncoding::UTF16->encode(getUnownedSlice(), buf); break; case 4: - Slang::Encoding::UTF32->GetBytes(buf, *this); + Slang::CharEncoding::UTF32->encode(getUnownedSlice(), buf); break; default: |
