File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -440,7 +440,7 @@ utf16string __cdecl conversions::latin1_to_utf16(const std::string &s)
440
440
dest.resize (s.size ());
441
441
for (size_t i = 0 ; i < s.size (); ++i)
442
442
{
443
- dest[i] = utf16char (s[i]);
443
+ dest[i] = utf16char (static_cast < unsigned char >( s[i]) );
444
444
}
445
445
return dest;
446
446
}
Original file line number Diff line number Diff line change @@ -278,13 +278,22 @@ TEST(utf8_to_utf16_errors)
278
278
279
279
TEST (latin1_to_utf16)
280
280
{
281
- // TODO: find some string that actually uses something unique to the Latin1 code page.
282
- std::string str_latin1 (" This is a test" );
283
- utf16string str_utf16 = utility::conversions::latin1_to_utf16 (str_latin1);
284
-
285
- for (size_t i = 0 ; i < str_latin1.size (); ++i)
281
+ char in[256 ] = { 0 };
282
+ char16_t expectedResult[256 ] = { 0 };
283
+ for (size_t i = 0 ; i < 256 ; ++i)
284
+ {
285
+ in[i] = static_cast <char >(i);
286
+ expectedResult[i] = static_cast <char16_t >(i);
287
+ }
288
+
289
+ std::string str_latin1 (in, 256 );
290
+
291
+ auto actualResult = utility::conversions::latin1_to_utf16 (str_latin1);
292
+
293
+ VERIFY_ARE_EQUAL (str_latin1.size (), actualResult.size ());
294
+ for (size_t i = 0 ; i < actualResult.size (); ++i)
286
295
{
287
- VERIFY_ARE_EQUAL ((utf16char)str_latin1 [i], str_utf16 [i]);
296
+ VERIFY_ARE_EQUAL (expectedResult [i], actualResult [i]);
288
297
}
289
298
}
290
299
You can’t perform that action at this time.
0 commit comments