File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ Author: Daniel Kroening, kroening@kroening.com
9
9
#include < cstring>
10
10
#include < locale>
11
11
#include < codecvt>
12
+ #include < sstream>
13
+ #include < iomanip>
12
14
13
15
#include " unicode.h"
14
16
@@ -277,19 +279,20 @@ std::wstring utf8_to_utf16_little_endian(const std::string& in)
277
279
278
280
std::string utf16_little_endian_to_ascii (const std::wstring& in)
279
281
{
280
- std::string result;
282
+ std::ostringstream result;
281
283
std::locale loc;
282
284
for (const auto c : in)
283
285
{
284
286
if (c<=255 && isprint (c, loc))
285
- result+= (unsigned char )c;
287
+ result << (unsigned char )c;
286
288
else
287
289
{
288
- result+=" \\ u" ;
289
- char hex[5 ];
290
- snprintf (hex, sizeof (hex), " %04x" , (wchar_t )c);
291
- result+=hex;
290
+ result << " \\ u"
291
+ << std::hex
292
+ << std::setw (4 )
293
+ << std::setfill (' 0' )
294
+ << (unsigned int )c;
292
295
}
293
296
}
294
- return result;
297
+ return result. str () ;
295
298
}
You can’t perform that action at this time.
0 commit comments