Remove unnecessary `UTF8GetBytes()` helper

This commit is contained in:
Susko3 2024-04-16 13:01:13 +02:00
parent 72a002ead0
commit 8e0066d7f7
2 changed files with 0 additions and 25 deletions

View File

@ -14,19 +14,6 @@ namespace SDL3.Tests
{
Console.OutputEncoding = Encoding.UTF8;
unsafe
{
// Encoding.UTF8.GetBytes can churn out null pointers and doesn't guarantee null termination
fixed (byte* badPointer = Encoding.UTF8.GetBytes(""))
Debug.Assert(badPointer == null);
fixed (byte* pointer = UTF8GetBytes(""))
{
Debug.Assert(pointer != null);
Debug.Assert(pointer[0] == '\0');
}
}
SDL_SetHint(SDL_HINT_WINDOWS_CLOSE_ON_ALT_F4, "null byte \0 in string"u8);
Debug.Assert(SDL_GetHint(SDL_HINT_WINDOWS_CLOSE_ON_ALT_F4) == "null byte ");

View File

@ -27,17 +27,5 @@ namespace SDL
return s;
}
/// <summary>
/// UTF8 encodes a managed <c>string</c> to a <c>byte</c> array suitable for use in <c>ReadOnlySpan&lt;byte&gt;</c> parameters of SDL functions.
/// </summary>
/// <param name="s">The <c>string</c> to encode.</param>
/// <returns>A null-terminated byte array.</returns>
public static byte[] UTF8GetBytes(string s)
{
byte[] array = Encoding.UTF8.GetBytes(s + '\0');
Debug.Assert(array[^1] == '\0');
return array;
}
}
}