This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
ARPlusSystem/ARPlusSystem-250418/Library/PackageCache/com.unity.xr.arcore@4.2.10/Runtime/StringExtensions.cs

26 lines
746 B
C#

using System;
using System.Text;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
namespace UnityEngine.XR.ARCore
{
static class StringExtensions
{
public static unsafe NativeArray<byte> ToBytes(this string @string, Encoding encoding, Allocator allocator)
{
if (@string == null)
throw new ArgumentNullException(nameof(@string));
var byteCount = encoding.GetByteCount(@string);
var bytes = new NativeArray<byte>(byteCount + 1, allocator);
fixed (char* chars = @string)
{
encoding.GetBytes(chars, @string.Length, (byte*)bytes.GetUnsafePtr(), byteCount);
}
return bytes;
}
}
}