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 < iomanip>
13
+ #include < sstream>
12
14
13
15
#include " unicode.h"
14
16
@@ -282,19 +284,20 @@ std::wstring utf8_to_utf16_little_endian(const std::string& in)
282
284
283
285
std::string utf16_little_endian_to_ascii (const std::wstring& in)
284
286
{
285
- std::string result;
287
+ std::ostringstream result;
286
288
std::locale loc;
287
289
for (const auto c : in)
288
290
{
289
291
if (c<=255 && isprint (c, loc))
290
- result+= (unsigned char )c;
292
+ result << (unsigned char )c;
291
293
else
292
294
{
293
- result+=" \\ u" ;
294
- char hex[5 ];
295
- snprintf (hex, sizeof (hex), " %04x" , (wchar_t )c);
296
- result+=hex;
295
+ result << " \\ u"
296
+ << std::hex
297
+ << std::setw (4 )
298
+ << std::setfill (' 0' )
299
+ << (unsigned int )c;
297
300
}
298
301
}
299
- return result;
302
+ return result. str () ;
300
303
}
You can’t perform that action at this time.
0 commit comments