mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
[Fonts] Add Encoding.GetString(ReadOnlySpan<byte>) polyfill
This commit is contained in:
parent
ce5dc7c1a1
commit
4ad6bfc74e
20
src/UglyToad.PdfPig.Fonts/Polyfills/EncodingExtensions.cs
Normal file
20
src/UglyToad.PdfPig.Fonts/Polyfills/EncodingExtensions.cs
Normal 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
|
Loading…
Reference in New Issue
Block a user