|
|
@ -31,6 +31,12 @@ void ucstring::toString(std::string &str) const
|
|
|
|
|
|
|
|
|
|
|
|
std::string ucstring::toUtf8() const
|
|
|
|
std::string ucstring::toUtf8() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(NL_OS_WINDOWS)
|
|
|
|
|
|
|
|
// Use OS implementation
|
|
|
|
|
|
|
|
nlctassert(sizeof(wchar_t) == sizeof(ucchar));
|
|
|
|
|
|
|
|
nlctassert(sizeof(wchar_t) == sizeof(uint16));
|
|
|
|
|
|
|
|
return NLMISC::wideToUtf8(static_cast<const std::wstring &>(*this));
|
|
|
|
|
|
|
|
#else
|
|
|
|
std::string res;
|
|
|
|
std::string res;
|
|
|
|
ucstring::const_iterator first(begin()), last(end());
|
|
|
|
ucstring::const_iterator first(begin()), last(end());
|
|
|
|
for (; first != last; ++first)
|
|
|
|
for (; first != last; ++first)
|
|
|
@ -65,10 +71,20 @@ std::string ucstring::toUtf8() const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ucstring::fromUtf8(const std::string &stringUtf8)
|
|
|
|
void ucstring::fromUtf8(const std::string &stringUtf8)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(NL_OS_WINDOWS)
|
|
|
|
|
|
|
|
// Use OS implementation
|
|
|
|
|
|
|
|
nlctassert(sizeof(wchar_t) == sizeof(ucchar));
|
|
|
|
|
|
|
|
nlctassert(sizeof(wchar_t) == sizeof(uint16));
|
|
|
|
|
|
|
|
nlctassert(sizeof(std::wstring) == sizeof(ucstring)); // These can be swapped on Windows
|
|
|
|
|
|
|
|
static_cast<std::wstring &>(*this) = nlmove(NLMISC::utf8ToWide(stringUtf8));
|
|
|
|
|
|
|
|
if (stringUtf8.size() && !size())
|
|
|
|
|
|
|
|
rawCopy(stringUtf8);
|
|
|
|
|
|
|
|
#else
|
|
|
|
// clear the string
|
|
|
|
// clear the string
|
|
|
|
erase();
|
|
|
|
erase();
|
|
|
|
|
|
|
|
|
|
|
@ -146,6 +162,7 @@ void ucstring::fromUtf8(const std::string &stringUtf8)
|
|
|
|
push_back(code);
|
|
|
|
push_back(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ucstring::rawCopy(const std::string &str)
|
|
|
|
void ucstring::rawCopy(const std::string &str)
|
|
|
|