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>.8B30AFDCF07C4ABDFE0FAF65F79FC40A2E9AC497C42B1BA5C996BDFB3F6EC2F6, 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;
}
}
}