[Fonts] Add Encoding.GetString(ReadOnlySpan<byte>) polyfill

This commit is contained in:
Jason Nelson 2024-04-01 21:47:24 -07:00 committed by BobLd
parent ce5dc7c1a1
commit 4ad6bfc74e

View File

@ -0,0 +1,20 @@
#if NETFRAMEWORK || NETSTANDARD2_0
namespace System.Text;
internal static class EncodingExtensions
{
public static string GetString(this Encoding encoding, ReadOnlySpan<byte> bytes)
{
if (bytes.IsEmpty)
{
return string.Empty;
}
// NOTE: this can be made allocation free by introducing unsafe
return encoding.GetString(bytes.ToArray());
}
}
#endif