mirror of
https://github.com/Ryujinx/SDL2-CS.git
synced 2025-03-04 20:59:40 +00:00
Allow Utf8EncodeHeap to return NULL, clean up Utf8Size
This commit is contained in:
parent
e316ae5cfd
commit
00c94a24eb
12
src/SDL2.cs
12
src/SDL2.cs
|
@ -48,7 +48,11 @@ namespace SDL2
|
||||||
/* Used for stack allocated string marshaling. */
|
/* Used for stack allocated string marshaling. */
|
||||||
internal static int Utf8Size(string str)
|
internal static int Utf8Size(string str)
|
||||||
{
|
{
|
||||||
return str != null ? (str.Length * 4) + 1 : 0;
|
if (str == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (str.Length * 4) + 1;
|
||||||
}
|
}
|
||||||
internal static unsafe byte* Utf8Encode(string str, byte* buffer, int bufferSize)
|
internal static unsafe byte* Utf8Encode(string str, byte* buffer, int bufferSize)
|
||||||
{
|
{
|
||||||
|
@ -68,7 +72,11 @@ namespace SDL2
|
||||||
*/
|
*/
|
||||||
internal static unsafe byte* Utf8EncodeHeap(string str)
|
internal static unsafe byte* Utf8EncodeHeap(string str)
|
||||||
{
|
{
|
||||||
Debug.Assert(str != null);
|
if (str == null)
|
||||||
|
{
|
||||||
|
return (byte*) 0;
|
||||||
|
}
|
||||||
|
|
||||||
int bufferSize = Utf8Size(str);
|
int bufferSize = Utf8Size(str);
|
||||||
byte* buffer = (byte*) Marshal.AllocHGlobal(bufferSize);
|
byte* buffer = (byte*) Marshal.AllocHGlobal(bufferSize);
|
||||||
fixed (char* strPtr = str)
|
fixed (char* strPtr = str)
|
||||||
|
|
Loading…
Reference in a new issue