Test UTF8ToUTF16 and UTF16ToUTF8.

This commit is contained in:
Victor Zverovich 2014-04-30 07:38:43 -07:00
parent 089974eb92
commit c16217bf9b
3 changed files with 21 additions and 3 deletions

View File

@ -230,6 +230,24 @@ TEST(UtilTest, CountDigits) {
TestCountDigits(uint64_t());
}
#ifdef _WIN32
TEST(UtilTest, UTF16ToUTF8) {
std::string s = "ёжик";
UTF16ToUTF8 u(L"\x0451\x0436\x0438\x043A");
EXPECT_EQ(s, str(u));
EXPECT_EQ(s.size(), u.size());
}
TEST(UtilTest, UTF8ToUTF16) {
std::string s = "лошадка";
UTF8ToUTF16 u(s.c_str());
EXPECT_EQ(L"\x043B\x043E\x0448\x0430\x0434\x043A\x0430", str(u));
EXPECT_EQ(7, u.size());
}
// TODO: test UTF16ToUTF8::Convert
#endif // _WIN32
class TestString {
private:
std::string value_;

View File

@ -244,7 +244,7 @@ void fmt::internal::FormatSystemErrorMessage(
reinterpret_cast<LPWSTR>(system_message.ptr()), 0, 0)) {
UTF16ToUTF8 utf8_message;
if (!utf8_message.Convert(system_message.c_str())) {
out << message << ": " << utf8_message;
out << message << ": " << c_str(utf8_message);
return;
}
}

View File

@ -467,7 +467,7 @@ class UTF8ToUTF16 {
public:
explicit UTF8ToUTF16(StringRef s);
operator const wchar_t*() const { return &buffer_[0]; }
operator WStringRef() const { return WStringRef(&buffer_[0], size()); }
size_t size() const { return buffer_.size() - 1; }
};
@ -480,7 +480,7 @@ class UTF16ToUTF8 {
public:
UTF16ToUTF8() {}
explicit UTF16ToUTF8(WStringRef s);
operator const char*() const { return &buffer_[0]; }
operator StringRef() const { return StringRef(&buffer_[0], size()); }
size_t size() const { return buffer_.size() - 1; }
// Performs conversion returning a system error code instead of