mirror of https://github.com/SeanOMik/libki.git
dml: Replace usage of wchar_t with char16_t
This commit is contained in:
parent
2e17370337
commit
2f56518b66
|
@ -13,7 +13,7 @@ namespace dml
|
|||
typedef int32_t INT;
|
||||
typedef uint32_t UINT;
|
||||
typedef std::string STR;
|
||||
typedef std::wstring WSTR;
|
||||
typedef std::u16string WSTR;
|
||||
typedef float FLT;
|
||||
typedef double DBL;
|
||||
typedef uint64_t GID;
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace dml
|
|||
if (data.buff[0] == ((m_value.length() & 0xFF00) >> 8))
|
||||
std::reverse(&data.buff[0], &data.buff[1]);
|
||||
ostream.write(data.buff, sizeof(USHRT));
|
||||
ostream.write((char *)m_value.c_str(), m_value.length() * sizeof(wchar_t));
|
||||
ostream.write((char *)m_value.c_str(), m_value.length() * sizeof(char16_t));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -29,22 +29,22 @@ namespace dml
|
|||
std::reverse(&length_data.buff[0], &length_data.buff[1]);
|
||||
|
||||
// Read the data into a buffer
|
||||
size_t length = length_data.value * sizeof(wchar_t);
|
||||
char *data = new char[length + sizeof(wchar_t)]{ 0 };
|
||||
size_t length = length_data.value * sizeof(char16_t);
|
||||
char *data = new char[length + sizeof(char16_t)]{ 0 };
|
||||
istream.read(data, length);
|
||||
for (int i = 0; i < length; i += 2)
|
||||
{
|
||||
if (endianness_check.buff[0] == 0x01)
|
||||
std::reverse(&data[i], &data[i + 1]);
|
||||
}
|
||||
m_value = WSTR((wchar_t *)data);
|
||||
m_value = WSTR((char16_t *)data);
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
template <>
|
||||
size_t WStrField::get_size() const
|
||||
{
|
||||
return sizeof(USHRT) + (m_value.length() * sizeof(wchar_t));
|
||||
return sizeof(USHRT) + (m_value.length() * sizeof(char16_t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ TEST_CASE("Field Serialization", "[dml]")
|
|||
|
||||
SECTION("WSTR Fields")
|
||||
{
|
||||
record->add_field<WSTR>("TestWStr")->set_value(L"TEST");
|
||||
record->add_field<WSTR>("TestWStr")->set_value(u"TEST");
|
||||
record->write_to(ss);
|
||||
|
||||
union
|
||||
|
@ -119,9 +119,10 @@ TEST_CASE("Field Serialization", "[dml]")
|
|||
memcpy(length_bytes.buff, ss.str().data(), 2);
|
||||
REQUIRE(length_bytes.length == 0x4);
|
||||
|
||||
wchar_t value_buff[5] = { 0 };
|
||||
char16_t value_buff[5] = { 0 };
|
||||
memcpy(value_buff, ss.str().substr(2).data(), 8);
|
||||
REQUIRE(wcscmp(value_buff, L"TEST") == 0);
|
||||
std::u16string value(value_buff);
|
||||
REQUIRE(value == u"TEST");
|
||||
}
|
||||
|
||||
SECTION("FLT Fields")
|
||||
|
@ -227,13 +228,13 @@ TEST_CASE("Field Deserialization", "[dml]")
|
|||
{
|
||||
char buff[10];
|
||||
memcpy(buff, "\x04\x00", sizeof(USHRT));
|
||||
memcpy(&buff[2], (char *)L"TEST", 8);
|
||||
memcpy(&buff[2], (char *)u"TEST", 8);
|
||||
ss.write(buff, 10);
|
||||
ss.seekg(std::stringstream::beg);
|
||||
|
||||
auto *field = record->add_field<WSTR>("TestWStr");
|
||||
record->read_from(ss);
|
||||
REQUIRE(field->get_value() == L"TEST");
|
||||
REQUIRE(field->get_value() == u"TEST");
|
||||
}
|
||||
|
||||
SECTION("FLT Fields")
|
||||
|
|
Loading…
Reference in New Issue