-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcsxutils.cpp
35 lines (30 loc) · 866 Bytes
/
csxutils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "csxutils.h"
#include <locale>
#include <codecvt>
CSXUtils::CSXUtils()
{
}
std::u16string CSXUtils::to_u16string(int const &i)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian>, char16_t> conv;
return conv.from_bytes(std::to_string(i));
}
std::u16string CSXUtils::read_unicode_string(Stream* str)
{
/*char16_t buf[1024];
uint32_t str_len;
str->read(&str_len, sizeof(uint32_t));
str->read(buf, str_len * sizeof(char16_t));
buf[str_len] = u'\0';
std::u16string s16 = buf;
std::string res = conv.to_bytes(s16);
return res;*/
char16_t buf[1024];
uint32_t str_len;
str->read(&str_len, sizeof(uint32_t));
str->read(buf, str_len * sizeof(char16_t));
//for (uint32_t i=1 ; i<str_len ; ++i)
// buf[i] = buf[i*2];
buf[str_len] = u'\0';
return buf;
}