Watch
2
0
Fork
You've already forked raylib-cs
0

Seperate UTF8 from Ansi

This commit is contained in:
Nickolas McDonald 2023-08-11 15:43:15 -04:00
commit be61ce992b
5 changed files with 102 additions and 49 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);
}
}