Skip to content

Commit

Permalink
Vutils
Browse files Browse the repository at this point in the history
  • Loading branch information
vic4key committed Sep 13, 2023
1 parent 641aca1 commit d8abdf5
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions src/details/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,30 @@ std::unique_ptr<std::string> vuapi FileSystemA::read_as_string()
return nullptr;
}

auto p = (char*)buffer->pointer();
std::unique_ptr<std::string> result(new std::string);

if (text_encoding == text_encoding::TE_UTF8_BOM)
if (text_encoding == text_encoding::TE_UTF16_LE ||
text_encoding == text_encoding::TE_UTF16_BE ||
text_encoding == text_encoding::TE_UTF16_LE_BOM ||
text_encoding == text_encoding::TE_UTF16_BE_BOM)
{
p += 3; /* remove BOM */
std::wstring tmp((wchar*)(buffer->bytes() + 2), (buffer->size() - 2) / 2);
result->assign(std::move(to_string_A(tmp, true))); // remove bom
}
else if (text_encoding == text_encoding::TE_UTF8)
{
std::string tmp((char*)buffer->bytes(), buffer->size());
result->assign(std::move(tmp));
}
else if (text_encoding == text_encoding::TE_UTF8_BOM)
{
std::string tmp((char*)buffer->bytes() + 3, buffer->size() - 3); // remove bom
result->assign(std::move(tmp));
}
else
{
assert(0);
}

std::unique_ptr<std::string> result(new std::string);

result->assign(p);

return result;
}
Expand Down Expand Up @@ -368,16 +382,30 @@ std::unique_ptr<std::wstring> vuapi FileSystemW::read_as_string()
return nullptr;
}

auto p = (wchar*)buffer->pointer();
std::unique_ptr<std::wstring> result(new std::wstring);

if (text_encoding == text_encoding::TE_UTF16_LE_BOM || text_encoding == text_encoding::TE_UTF16_BE_BOM)
if (text_encoding == text_encoding::TE_UTF16_LE ||
text_encoding == text_encoding::TE_UTF16_BE ||
text_encoding == text_encoding::TE_UTF16_LE_BOM ||
text_encoding == text_encoding::TE_UTF16_BE_BOM)
{
p = (wchar*)((char*)buffer->pointer() + 2); /* remove BOM */
std::wstring tmp((wchar*)(buffer->bytes() + 2), (buffer->size() - 2) / 2);
result->assign(std::move(tmp)); // remove bom
}
else if (text_encoding == text_encoding::TE_UTF8)
{
std::string tmp((char*)buffer->bytes(), buffer->size());
result->assign(std::move(to_string_W(tmp)));
}
else if (text_encoding == text_encoding::TE_UTF8_BOM)
{
std::string tmp((char*)buffer->bytes() + 3, buffer->size() - 3); // remove bom
result->assign(std::move(to_string_W(tmp)));
}
else
{
assert(0);
}

std::unique_ptr<std::wstring> result(new std::wstring);

result->assign(p);

return result;
}
Expand Down

0 comments on commit d8abdf5

Please sign in to comment.