// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Runtime.InteropServices; namespace SDL { public static unsafe partial class SDL3 { /// /// Allocates a managed string and copies all characters up to the first null character from an unmanaged UTF-8 string into it. /// /// The address of the first character of the unmanaged string. /// Whether to free the pointer after copying the string. /// /// A managed string that holds a copy of the unmanaged string if the value of the parameter is not null; otherwise, this method returns null. /// public static string? PtrToStringUTF8(byte* ptr, bool free = false) { string? s = Marshal.PtrToStringUTF8((IntPtr)ptr); if (free) SDL_free(ptr); return s; } } }