diff --git a/Raylib-cs/Utf8String.cs b/Raylib-cs/types/native/Utf8String.cs similarity index 89% rename from Raylib-cs/Utf8String.cs rename to Raylib-cs/types/native/Utf8String.cs index 1b5a57c..cad8f5d 100644 --- a/Raylib-cs/Utf8String.cs +++ b/Raylib-cs/types/native/Utf8String.cs @@ -66,8 +66,8 @@ public readonly ref struct Utf8String public static Utf8String FromSpan(ReadOnlySpan span) { if ( - (span.Length > 0) - && (span[^1] != 0) + span.Length > 0 + && span[^1] != 0 ) { throw new ArgumentException("zero terminator required"); @@ -82,10 +82,8 @@ public readonly ref struct Utf8String { return new Utf8String(ReadOnlySpan.Empty); } - else - { - return new Utf8String(s.ToUtf8String()); - } + + return new Utf8String(s.ToUtf8String()); } static unsafe long GetLength(byte* p) @@ -112,14 +110,7 @@ public readonly ref struct Utf8String /// public static unsafe Utf8String FromPtr(byte* p) { - if (p == null) - { - return new Utf8String(ReadOnlySpan.Empty); - } - else - { - return new Utf8String(FindZeroTerminator(p)); - } + return p == null ? new Utf8String(ReadOnlySpan.Empty) : new Utf8String(FindZeroTerminator(p)); } // TODO maybe remove this and just use FromSpan? @@ -144,30 +135,28 @@ public readonly ref struct Utf8String { return new Utf8String(ReadOnlySpan.Empty); } - else - { - // the given len does NOT include the zero terminator - var sp = new ReadOnlySpan(p, len + 1); - return FromSpan(sp); - } + + // the given len does NOT include the zero terminator + var sp = new ReadOnlySpan(p, len + 1); + return FromSpan(sp); } public static unsafe Utf8String FromIntPtr(IntPtr p) { - if (p == IntPtr.Zero) - { - return new Utf8String(ReadOnlySpan.Empty); - } - else - { - return new Utf8String(FindZeroTerminator((byte*)(p.ToPointer()))); - } + return p == IntPtr.Zero ? new Utf8String(ReadOnlySpan.Empty) : new Utf8String(FindZeroTerminator((byte*)p.ToPointer())); } + /// + /// UTF16 String representation + /// Returns "NUL" on Null native type + /// + /// public override string ToString() { if (sp.Length == 0) { + // object.ToString() should never thrown + // throw new NullReferenceException(); return "NUL"; }