up to date with 08126b26b1
This commit is contained in:
30
src/Ryujinx.Graphics.Metal/StringHelper.cs
Normal file
30
src/Ryujinx.Graphics.Metal/StringHelper.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using SharpMetal.Foundation;
|
||||
using SharpMetal.ObjectiveCCore;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
[SupportedOSPlatform("macos")]
|
||||
public class StringHelper
|
||||
{
|
||||
public static NSString NSString(string source)
|
||||
{
|
||||
return new(ObjectiveC.IntPtr_objc_msgSend(new ObjectiveCClass("NSString"), "stringWithUTF8String:", source));
|
||||
}
|
||||
|
||||
public static unsafe string String(NSString source)
|
||||
{
|
||||
char[] sourceBuffer = new char[source.Length];
|
||||
fixed (char* pSourceBuffer = sourceBuffer)
|
||||
{
|
||||
ObjectiveC.bool_objc_msgSend(source,
|
||||
"getCString:maxLength:encoding:",
|
||||
pSourceBuffer,
|
||||
source.MaximumLengthOfBytes(NSStringEncoding.UTF16) + 1,
|
||||
(ulong)NSStringEncoding.UTF16);
|
||||
}
|
||||
|
||||
return new string(sourceBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user