diff --git a/src/ImGui.NET/ImGui.Manual.cs b/src/ImGui.NET/ImGui.Manual.cs index 84926a6..cec21cf 100644 --- a/src/ImGui.NET/ImGui.Manual.cs +++ b/src/ImGui.NET/ImGui.Manual.cs @@ -403,7 +403,7 @@ namespace ImGuiNET { int textToCopyLen = length.HasValue ? length.Value : text.Length; - textByteCount = Util.CalcUtf8(text, start, textToCopyLen); + textByteCount = Util.CalcSizeInUtf8(text, start, textToCopyLen); if (textByteCount > Util.StackAllocationSizeLimit) { nativeTextStart = Util.Allocate(textByteCount + 1); @@ -414,7 +414,7 @@ namespace ImGuiNET nativeTextStart = nativeTextStackBytes; } - int nativeTextOffset = Util.GetUtf8(text, nativeTextStart, textByteCount, start, textToCopyLen); + int nativeTextOffset = Util.GetUtf8(text, start, textToCopyLen, nativeTextStart, textByteCount); nativeTextStart[nativeTextOffset] = 0; nativeTextEnd = nativeTextStart + nativeTextOffset; } diff --git a/src/ImGui.NET/Util.cs b/src/ImGui.NET/Util.cs index 0df92f0..1753d30 100644 --- a/src/ImGui.NET/Util.cs +++ b/src/ImGui.NET/Util.cs @@ -32,8 +32,10 @@ namespace ImGuiNET } internal static byte* Allocate(int byteCount) => (byte*)Marshal.AllocHGlobal(byteCount); + internal static void Free(byte* ptr) => Marshal.FreeHGlobal((IntPtr)ptr); - internal static int CalcUtf8(string s, int start, int length) + + internal static int CalcSizeInUtf8(string s, int start, int length) { if (start > s.Length - 1 || length > s.Length || start + length > s.Length) { @@ -54,7 +56,7 @@ namespace ImGuiNET } } - internal static int GetUtf8(string s, byte* utf8Bytes, int utf8ByteCount, int start = 0, int length = 0) + internal static int GetUtf8(string s, int start, int length, byte* utf8Bytes, int utf8ByteCount) { fixed (char* utf16Ptr = s) {