Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UnicodeUtility.cs
Go to the documentation of this file.
2
3namespace System.Text;
4
5internal static class UnicodeUtility
6{
7 public static int GetPlane(uint codePoint)
8 {
9 return (int)(codePoint >> 16);
10 }
11
12 public static uint GetScalarFromUtf16SurrogatePair(uint highSurrogateCodePoint, uint lowSurrogateCodePoint)
13 {
14 return (highSurrogateCodePoint << 10) + lowSurrogateCodePoint - 56613888;
15 }
16
17 public static int GetUtf16SequenceLength(uint value)
18 {
19 value -= 65536;
20 value += 33554432;
21 value >>= 24;
22 return (int)value;
23 }
24
25 [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 public static void GetUtf16SurrogatesFromSupplementaryPlaneScalar(uint value, out char highSurrogateCodePoint, out char lowSurrogateCodePoint)
27 {
28 highSurrogateCodePoint = (char)(value + 56557568 >> 10);
29 lowSurrogateCodePoint = (char)((value & 0x3FF) + 56320);
30 }
31
32 public static int GetUtf8SequenceLength(uint value)
33 {
34 int num = (int)(value - 2048) >> 31;
35 value ^= 0xF800u;
36 value -= 63616;
37 value += 67108864;
38 value >>= 24;
39 return (int)value + num * 2;
40 }
41
42 [MethodImpl(MethodImplOptions.AggressiveInlining)]
43 public static bool IsAsciiCodePoint(uint value)
44 {
45 return value <= 127;
46 }
47
48 [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 public static bool IsBmpCodePoint(uint value)
50 {
51 return value <= 65535;
52 }
53
54 [MethodImpl(MethodImplOptions.AggressiveInlining)]
55 public static bool IsHighSurrogateCodePoint(uint value)
56 {
57 return IsInRangeInclusive(value, 55296u, 56319u);
58 }
59
60 [MethodImpl(MethodImplOptions.AggressiveInlining)]
61 public static bool IsInRangeInclusive(uint value, uint lowerBound, uint upperBound)
62 {
63 return value - lowerBound <= upperBound - lowerBound;
64 }
65
66 [MethodImpl(MethodImplOptions.AggressiveInlining)]
67 public static bool IsLowSurrogateCodePoint(uint value)
68 {
69 return IsInRangeInclusive(value, 56320u, 57343u);
70 }
71
72 [MethodImpl(MethodImplOptions.AggressiveInlining)]
73 public static bool IsSurrogateCodePoint(uint value)
74 {
75 return IsInRangeInclusive(value, 55296u, 57343u);
76 }
77
78 [MethodImpl(MethodImplOptions.AggressiveInlining)]
79 public static bool IsValidCodePoint(uint codePoint)
80 {
81 return codePoint <= 1114111;
82 }
83
84 [MethodImpl(MethodImplOptions.AggressiveInlining)]
85 public static bool IsValidUnicodeScalar(uint value)
86 {
87 return ((value - 1114112) ^ 0xD800) >= 4293855232u;
88 }
89}
static bool IsSurrogateCodePoint(uint value)
static bool IsValidUnicodeScalar(uint value)
static void GetUtf16SurrogatesFromSupplementaryPlaneScalar(uint value, out char highSurrogateCodePoint, out char lowSurrogateCodePoint)
static bool IsInRangeInclusive(uint value, uint lowerBound, uint upperBound)
static int GetUtf8SequenceLength(uint value)
static uint GetScalarFromUtf16SurrogatePair(uint highSurrogateCodePoint, uint lowSurrogateCodePoint)
static int GetUtf16SequenceLength(uint value)
static bool IsValidCodePoint(uint codePoint)
static bool IsAsciiCodePoint(uint value)
static bool IsBmpCodePoint(uint value)
static bool IsHighSurrogateCodePoint(uint value)
static int GetPlane(uint codePoint)
static bool IsLowSurrogateCodePoint(uint value)