diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index f0e1634..654338d 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -1,7 +1,10 @@ using System; +using System.Buffers; using System.Numerics; using System.Runtime.InteropServices; using System.Security; +using System.Text; +using System.Text.Unicode; using System.Xml; namespace Raylib_cs @@ -1617,34 +1620,99 @@ namespace Raylib_cs /// Append text at specific position and move cursor! [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void TextAppend(ref char text, string append, ref int position); + public static extern void TextAppend(byte* text, byte* append, int* position); + + public static void TextAppend(Utf8String text, Utf8String append, int position) + { + fixed (byte* p1 = text) + { + fixed (byte* p2 = append) + { + TextAppend(p1,p2, &position); + } + } + } + /// Get Pascal case notation version of provided string [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern string TextToPascal(string text); + public static extern byte* TextToPascal(byte* text); + public static Utf8String TextToPascal(Utf8String text) + { + fixed (byte* p1 = text) + { + return Utf8String.FromPtr(TextToPascal(p1)); + } + } /// Get integer value from text (negative values not supported) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int TextToInteger(string text); + public static extern int TextToInteger(byte* text); + + public static int TextToInteger(Utf8String text) + { + fixed (byte* p1 = text) + { + return TextToInteger(p1); + } + } /// Encode text codepoint into utf8 text (memory must be freed!) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern string TextToUtf8(string text, int length); + public static extern string TextToUtf8(byte* text, int length); + + public static string TextToUtf8(Utf8String text, int length) + { + fixed (byte* p1 = text) + { + return TextToUtf8(p1, length); + } + } // UTF8 text strings management functions /// Get all codepoints in a string, codepoints count returned by parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int* GetCodepoints(string text, ref int count); + public static extern int* LoadCodepoints(byte* text, int* count); + + public static ReadOnlySpan LoadCodepoints(Utf8String text, int count) + { + fixed (byte* p1 = text) + { + var points = LoadCodepoints(p1, &count); + return new ReadOnlySpan(points, count); + } + } /// Get total number of characters (codepoints) in a UTF8 encoded string [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetCodepointsCount(string text); + public static extern int GetCodepointsCount(byte* text); + + public static int GetCodepointsCount(Utf8String text) + { + fixed (byte* p1 = text) + { + return GetCodepointsCount(p1); + } + } /// Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int GetNextCodepoint(string text, ref int bytesProcessed); + public static extern int GetCodepoint(byte* text, int* bytesProcessed); + + /// Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure + /// single codepoint / "char" + public static Utf8String GetCodepoint(Utf8String text, int bytesProcessed) + { + fixed (byte* p1 = text) + { + // this probably wont work + var point = GetCodepoint(p1, &bytesProcessed); + var c = (byte*)&point; + return Utf8String.FromPtr(c); + } + } /// Encode codepoint into utf8 text (char array length returned as parameter) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]