mirror of
https://github.com/crskycode/GARbro.git
synced 2025-01-11 20:39:29 +08:00
(ReadString): support UTF-16 encodings.
This commit is contained in:
parent
ef5a060ee5
commit
97aed46293
@ -440,10 +440,23 @@ namespace GameRes
|
||||
{
|
||||
byte* s = m_mem + (offset - m_offset);
|
||||
uint string_length = 0;
|
||||
// enc.WindowsCodePage property might throw an exception for some encodings, while
|
||||
// CodePage is just a direct field access.
|
||||
if (enc.CodePage == 1200 || enc.CodePage == 1201) // for UTF-16 encodings stop marker is 2-bytes long
|
||||
{
|
||||
ushort* u = (ushort*)s;
|
||||
while (string_length + 1 < size && 0 != u[string_length >> 1])
|
||||
{
|
||||
string_length += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (string_length < size && 0 != s[string_length])
|
||||
{
|
||||
++string_length;
|
||||
}
|
||||
}
|
||||
return new string ((sbyte*)s, 0, (int)string_length, enc);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user