mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
Fixed UTF16/32 encoding issues regarding null termination
This commit is contained in:
parent
5fd9552331
commit
cf6ade5e45
4 changed files with 8 additions and 11 deletions
|
@ -132,7 +132,7 @@ namespace System
|
||||||
int allocSize = UTF16.GetEncodedLen(key);
|
int allocSize = UTF16.GetEncodedLen(key);
|
||||||
char16* encodedData = scope char16[allocSize]*;
|
char16* encodedData = scope char16[allocSize]*;
|
||||||
int encodedLen = UTF16.Encode(key, encodedData, allocSize);
|
int encodedLen = UTF16.Encode(key, encodedData, allocSize);
|
||||||
int byteLen = (encodedLen - 1) * 2;
|
int byteLen = encodedLen * 2;
|
||||||
Internal.MemCpy(data.GrowUnitialized(byteLen), encodedData, byteLen);
|
Internal.MemCpy(data.GrowUnitialized(byteLen), encodedData, byteLen);
|
||||||
|
|
||||||
data.Add((uint8)'='); data.Add((uint8)0);
|
data.Add((uint8)'='); data.Add((uint8)0);
|
||||||
|
@ -141,7 +141,7 @@ namespace System
|
||||||
allocSize = UTF16.GetEncodedLen(value);
|
allocSize = UTF16.GetEncodedLen(value);
|
||||||
encodedData = scope char16[allocSize]*;
|
encodedData = scope char16[allocSize]*;
|
||||||
encodedLen = UTF16.Encode(value, encodedData, allocSize);
|
encodedLen = UTF16.Encode(value, encodedData, allocSize);
|
||||||
byteLen = (encodedLen - 1) * 2;
|
byteLen = encodedLen * 2;
|
||||||
Internal.MemCpy(data.GrowUnitialized(byteLen), encodedData, byteLen);
|
Internal.MemCpy(data.GrowUnitialized(byteLen), encodedData, byteLen);
|
||||||
|
|
||||||
data.Add(0); data.Add(0); // Single UTF16 char
|
data.Add(0); data.Add(0); // Single UTF16 char
|
||||||
|
|
|
@ -2516,11 +2516,11 @@ namespace System
|
||||||
c_wchar* buf;
|
c_wchar* buf;
|
||||||
if (encodedLen < 128)
|
if (encodedLen < 128)
|
||||||
{
|
{
|
||||||
buf = scope:mixin c_wchar[encodedLen]* ( ? );
|
buf = scope:mixin c_wchar[encodedLen+1]* ( ? );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buf = new c_wchar[encodedLen]* ( ? );
|
buf = new c_wchar[encodedLen+1]* ( ? );
|
||||||
defer:mixin delete buf;
|
defer:mixin delete buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2528,6 +2528,7 @@ namespace System
|
||||||
UTF16.Encode(this, (.)buf, encodedLen);
|
UTF16.Encode(this, (.)buf, encodedLen);
|
||||||
else
|
else
|
||||||
UTF32.Encode(this, (.)buf, encodedLen);
|
UTF32.Encode(this, (.)buf, encodedLen);
|
||||||
|
buf[encodedLen] = 0;
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3805,15 +3806,16 @@ namespace System
|
||||||
char16* buf;
|
char16* buf;
|
||||||
if (encodedLen < 128)
|
if (encodedLen < 128)
|
||||||
{
|
{
|
||||||
buf = scope:mixin char16[encodedLen]* ( ? );
|
buf = scope:mixin char16[encodedLen+1]* ( ? );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buf = new char16[encodedLen]* ( ? );
|
buf = new char16[encodedLen+1]* ( ? );
|
||||||
defer:mixin delete buf;
|
defer:mixin delete buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
UTF16.Encode(this, buf, encodedLen);
|
UTF16.Encode(this, buf, encodedLen);
|
||||||
|
buf[encodedLen] = 0;
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,6 @@ namespace System.Text
|
||||||
else
|
else
|
||||||
len += 2;
|
len += 2;
|
||||||
}
|
}
|
||||||
len++; // null terminator
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +222,6 @@ namespace System.Text
|
||||||
EncodeChar((char16)(valLeft & 0x3FF) + 0xDC00);
|
EncodeChar((char16)(valLeft & 0x3FF) + 0xDC00);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EncodeChar(0);
|
|
||||||
|
|
||||||
int encodedLen = bufLen - bufLeft;
|
int encodedLen = bufLen - bufLeft;
|
||||||
if (bufLeft < 0)
|
if (bufLeft < 0)
|
||||||
|
|
|
@ -106,7 +106,6 @@ namespace System.Text
|
||||||
{
|
{
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
len++; // null terminator
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,10 +131,8 @@ namespace System.Text
|
||||||
|
|
||||||
for (var c in str.DecodedChars)
|
for (var c in str.DecodedChars)
|
||||||
{
|
{
|
||||||
|
|
||||||
EncodeChar((char32)c);
|
EncodeChar((char32)c);
|
||||||
}
|
}
|
||||||
EncodeChar(0);
|
|
||||||
|
|
||||||
int encodedLen = bufLen - bufLeft;
|
int encodedLen = bufLen - bufLeft;
|
||||||
if (bufLeft < 0)
|
if (bufLeft < 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue