2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-06-30 19:03:42 -04:00

[Fix #184] Seperate UTF8 from Ansi (#185)

This commit is contained in:
Nickolas McDonald
2023-08-12 17:59:46 -04:00
committed by GitHub
parent f4c70a2872
commit d067c6c0aa
4 changed files with 70 additions and 33 deletions

View File

@ -0,0 +1,36 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Converts text to a Ansi buffer for passing to native code
/// </summary>
public readonly ref struct AnsiBuffer
{
private readonly IntPtr data;
public AnsiBuffer(string text)
{
data = Marshal.StringToHGlobalAnsi(text);
}
public unsafe sbyte* AsPointer()
{
return (sbyte*)data.ToPointer();
}
public void Dispose()
{
Marshal.FreeHGlobal(data);
}
}
public static class AnsiStringUtils
{
public static AnsiBuffer ToAnsiBuffer(this string text)
{
return new AnsiBuffer(text);
}
}
}

View File

@ -1,19 +1,19 @@
using System;
using System.Text;
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Raylib_cs
{
/// <summary>
/// Converts text to a UTF8 buffer for passing to native code
/// </summary>
public ref struct UTF8Buffer
public readonly ref struct UTF8Buffer
{
private IntPtr data;
private readonly IntPtr data;
public UTF8Buffer(string text)
{
this.data = Marshal.StringToHGlobalAnsi(text);
data = Marshal.StringToCoTaskMemUTF8(text);
}
public unsafe sbyte* AsPointer()
@ -23,7 +23,7 @@ namespace Raylib_cs
public void Dispose()
{
Marshal.FreeHGlobal(data);
Marshal.ZeroFreeCoTaskMemUTF8(data);
}
}