2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-09-09 03:01:41 -04:00

Apply master changes and fix utf8 buffer naming

This commit is contained in:
2023-08-13 10:28:05 +01:00
18 changed files with 102 additions and 65 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)
public Utf8Buffer(string text)
{
_data = Marshal.StringToHGlobalAnsi(text);
_data = Marshal.StringToCoTaskMemUTF8(text);
}
public unsafe sbyte* AsPointer()
@@ -23,15 +23,15 @@ namespace Raylib_cs
public void Dispose()
{
Marshal.FreeHGlobal(_data);
Marshal.ZeroFreeCoTaskMemUTF8(_data);
}
}
public static class Utf8StringUtils
{
public static UTF8Buffer ToUTF8Buffer(this string text)
public static Utf8Buffer ToUtf8Buffer(this string text)
{
return new UTF8Buffer(text);
return new Utf8Buffer(text);
}
public static byte[] ToUtf8String(this string text)