Skip to content

Commit

Permalink
[Fonts] Add Encoding.GetString(ReadOnlySpan<byte>) polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon authored and BobLd committed Apr 12, 2024
1 parent ce5dc7c commit 4ad6bfc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/UglyToad.PdfPig.Fonts/Polyfills/EncodingExtensions.cs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4ad6bfc

Please sign in to comment.