ISO: optimize byteswap and utf16 string conversion
This commit is contained in:
+8
-15
@@ -102,24 +102,17 @@ std::optional<iso_fs_metadata> iso_read_directory_entry(fs::file& file, bool nam
|
|||||||
}
|
}
|
||||||
else if (names_in_ucs2) // for strings in joliet descriptor
|
else if (names_in_ucs2) // for strings in joliet descriptor
|
||||||
{
|
{
|
||||||
std::string new_file_name;
|
// characters are stored in big endian format.
|
||||||
int read = 0;
|
std::u16string utf16;
|
||||||
const u8* raw_str = reinterpret_cast<const u8*>(file_name.c_str());
|
utf16.resize(file_name_length / 2);
|
||||||
while (read < file_name_length)
|
|
||||||
|
const u16* raw = reinterpret_cast<const u16*>(file_name.data());
|
||||||
|
for (size_t i = 0; i < utf16.size(); ++i, raw++)
|
||||||
{
|
{
|
||||||
// characters are stored in big endian format.
|
utf16[i] = *reinterpret_cast<const be_t<u16>*>(raw);
|
||||||
const u16 upper = raw_str[read];
|
|
||||||
const u8 lower = raw_str[read + 1];
|
|
||||||
|
|
||||||
const u16 code_point = (upper << 8) + lower;
|
|
||||||
|
|
||||||
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> convert;
|
|
||||||
new_file_name += convert.to_bytes(code_point);
|
|
||||||
|
|
||||||
read += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file_name = new_file_name;
|
file_name = utf16_to_utf8(utf16);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_name.ends_with(";1"))
|
if (file_name.ends_with(";1"))
|
||||||
|
|||||||
Reference in New Issue
Block a user