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

[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
commit d067c6c0aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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);
}
}