Skip to content

Commit

Permalink
Fixing latin1 to UTF-16 convertion
Browse files Browse the repository at this point in the history
  • Loading branch information
pp555 committed Mar 31, 2016
1 parent 29ba42e commit 5d84d4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Release/src/utilities/asyncrt_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ utf16string __cdecl conversions::latin1_to_utf16(const std::string &s)
dest.resize(s.size());
for (size_t i = 0; i < s.size(); ++i)
{
dest[i] = utf16char(s[i]);
dest[i] = utf16char(static_cast<unsigned char>(s[i]));
}
return dest;
}
Expand Down
21 changes: 15 additions & 6 deletions Release/tests/functional/utils/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,22 @@ TEST(utf8_to_utf16_errors)

TEST(latin1_to_utf16)
{
// TODO: find some string that actually uses something unique to the Latin1 code page.
std::string str_latin1("This is a test");
utf16string str_utf16 = utility::conversions::latin1_to_utf16(str_latin1);

for (size_t i = 0; i < str_latin1.size(); ++i)
char in[256] = { 0 };
char16_t expectedResult[256] = { 0 };
for (size_t i = 0; i < 256; ++i)
{
in[i] = static_cast<char>(i);
expectedResult[i] = static_cast<char16_t>(i);
}

std::string str_latin1(in, 256);

auto actualResult = utility::conversions::latin1_to_utf16(str_latin1);

VERIFY_ARE_EQUAL(str_latin1.size(), actualResult.size());
for (size_t i = 0; i < actualResult.size(); ++i)
{
VERIFY_ARE_EQUAL((utf16char)str_latin1[i], str_utf16[i]);
VERIFY_ARE_EQUAL(expectedResult[i], actualResult[i]);
}
}

Expand Down

0 comments on commit 5d84d4c

Please sign in to comment.