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>.B3AC89EE9FC6DD6CE1B8349B23557D92E963EFB91DFB57E356869086CF3AB527, 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));
return ((byte)(128 | (scalar & 63)) << 8) | b;
}
if (scalar <= 65535) {
byte b2 = (byte)(224 | (scalar >> 12));
byte b3 = (byte)(128 | ((scalar >> 6) & 63));
return ((((byte)(128 | (scalar & 63)) << 8) | b3) << 8) | b2;
}
byte b4 = (byte)(240 | (scalar >> 18));
byte b5 = (byte)(128 | ((scalar >> 12) & 63));
byte b6 = (byte)(128 | ((scalar >> 6) & 63));
return ((((((byte)(128 | (scalar & 63)) << 8) | b6) << 8) | b5) << 8) | b4;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool IsSupplementaryCodePoint(int scalar)
{
return (scalar & -65536) != 0;
}
}
}