<PackageReference Include="System.Text.Encodings.Web" Version="7.0.0-preview.3.22175.4" />

UnicodeHelpers

static class UnicodeHelpers
using System.Runtime.CompilerServices; namespace System.Text.Unicode { internal static class UnicodeHelpers { internal const int UNICODE_LAST_CODEPOINT = 1114111; private unsafe static ReadOnlySpan<byte> DefinedCharsBitmapSpan => new ReadOnlySpan<byte>(&global::<PrivateImplementationDetails>.7933520BFAF34098049CC893E2B5321C47D8B0A806EF325556FBE7B2D9CB1F50, 8192); internal static ReadOnlySpan<byte> GetDefinedBmpCodePointsBitmapLittleEndian() { return DefinedCharsBitmapSpan; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void GetUtf16SurrogatePairFromAstralScalarValue(uint scalar, out char highSurrogate, out char lowSurrogate) { highSurrogate = (char)(scalar + 56557568 >> 10); lowSurrogate = (char)((scalar & 1023) + 56320); } internal static int GetUtf8RepresentationForScalarValue(uint scalar) { if (scalar <= 127) return (byte)scalar; if (scalar <= 2047) { byte b = (byte)(192 | (scalar >> 6)); byte b2 = (byte)(128 | (scalar & 63)); return (b2 << 8) | b; } if (scalar <= 65535) { byte b3 = (byte)(224 | (scalar >> 12)); byte b4 = (byte)(128 | ((scalar >> 6) & 63)); byte b5 = (byte)(128 | (scalar & 63)); return (((b5 << 8) | b4) << 8) | b3; } byte b6 = (byte)(240 | (scalar >> 18)); byte b7 = (byte)(128 | ((scalar >> 12) & 63)); byte b8 = (byte)(128 | ((scalar >> 6) & 63)); byte b9 = (byte)(128 | (scalar & 63)); return (((((b9 << 8) | b8) << 8) | b7) << 8) | b6; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool IsSupplementaryCodePoint(int scalar) { return (scalar & -65536) != 0; } } }