7 [__DynamicallyInvokable]
11 internal struct UnicodeDataHeader
14 internal char TableName;
17 internal ushort version;
20 internal uint OffsetToCategoriesIndex;
23 internal uint OffsetToCategoriesValue;
26 internal uint OffsetToNumbericIndex;
29 internal uint OffsetToDigitValue;
32 internal uint OffsetToNumbericValue;
35 [StructLayout(
LayoutKind.Sequential, Pack = 2)]
36 internal struct DigitValues
38 internal sbyte decimalDigit;
43 internal const char HIGH_SURROGATE_START =
'\ud800';
45 internal const char HIGH_SURROGATE_END =
'\udbff';
47 internal const char LOW_SURROGATE_START =
'\udc00';
49 internal const char LOW_SURROGATE_END =
'\udfff';
51 internal const int UNICODE_CATEGORY_OFFSET = 0;
53 internal const int BIDI_CATEGORY_OFFSET = 1;
55 private static bool s_initialized = InitTable();
58 private unsafe
static ushort* s_pCategoryLevel1Index;
61 private unsafe
static byte* s_pCategoriesValue;
64 private unsafe
static ushort* s_pNumericLevel1Index;
67 private unsafe
static byte* s_pNumericValues;
70 private unsafe
static DigitValues* s_pDigitValues;
72 internal const string UNICODE_INFO_FILE_NAME =
"charinfo.nlp";
74 internal const int UNICODE_PLANE01_START = 65536;
76 [SecuritySafeCritical]
77 private unsafe
static bool InitTable()
79 byte* globalizationResourceBytePtr = GlobalizationAssembly.GetGlobalizationResourceBytePtr(typeof(
CharUnicodeInfo).
Assembly,
"charinfo.nlp");
80 UnicodeDataHeader* ptr = (UnicodeDataHeader*)globalizationResourceBytePtr;
81 s_pCategoryLevel1Index = (ushort*)(globalizationResourceBytePtr + ptr->OffsetToCategoriesIndex);
82 s_pCategoriesValue = globalizationResourceBytePtr + ptr->OffsetToCategoriesValue;
83 s_pNumericLevel1Index = (ushort*)(globalizationResourceBytePtr + ptr->OffsetToNumbericIndex);
84 s_pNumericValues = globalizationResourceBytePtr + ptr->OffsetToNumbericValue;
85 s_pDigitValues = (DigitValues*)(globalizationResourceBytePtr + ptr->OffsetToDigitValue);
89 internal static int InternalConvertToUtf32(
string s,
int index)
91 if (index < s.Length - 1)
93 int num = s[index] - 55296;
94 if (num >= 0 && num <= 1023)
96 int num2 = s[index + 1] - 56320;
97 if (num2 >= 0 && num2 <= 1023)
99 return num * 1024 + num2 + 65536;
106 internal static int InternalConvertToUtf32(
string s,
int index, out
int charLength)
109 if (index < s.Length - 1)
111 int num = s[index] - 55296;
112 if (num >= 0 && num <= 1023)
114 int num2 = s[index + 1] - 56320;
115 if (num2 >= 0 && num2 <= 1023)
118 return num * 1024 + num2 + 65536;
125 internal static bool IsWhiteSpace(
string s,
int index)
138 internal static bool IsWhiteSpace(
char c)
151 [SecuritySafeCritical]
152 internal unsafe
static double InternalGetNumericValue(
int ch)
154 ushort num = s_pNumericLevel1Index[ch >> 8];
155 num = s_pNumericLevel1Index[num + ((ch >> 4) & 0xF)];
156 byte* ptr = (
byte*)(s_pNumericLevel1Index + (
int)num);
157 byte* ptr2 = s_pNumericValues + ptr[ch & 0xF] * 8;
158 if ((
long)ptr2 % 8 != 0
L)
160 double result =
default(
double);
161 byte* dest = (
byte*)(&result);
162 Buffer.Memcpy(dest, ptr2, 8);
165 return *(
double*)(s_pNumericValues + (
long)(int)ptr[ch & 0xF] * 8
L);
168 [SecuritySafeCritical]
169 internal unsafe
static DigitValues* InternalGetDigitValues(
int ch)
171 ushort num = s_pNumericLevel1Index[ch >> 8];
172 num = s_pNumericLevel1Index[num + ((ch >> 4) & 0xF)];
173 byte* ptr = (
byte*)(s_pNumericLevel1Index + (
int)num);
174 return s_pDigitValues + (int)ptr[ch & 0xF];
177 [SecuritySafeCritical]
178 internal unsafe
static sbyte InternalGetDecimalDigitValue(
int ch)
180 return InternalGetDigitValues(ch)->decimalDigit;
183 [SecuritySafeCritical]
184 internal unsafe
static sbyte InternalGetDigitValue(
int ch)
186 return InternalGetDigitValues(ch)->digit;
192 [__DynamicallyInvokable]
195 return InternalGetNumericValue(ch);
206 [__DynamicallyInvokable]
213 if (index < 0 || index >= s.Length)
217 return InternalGetNumericValue(InternalConvertToUtf32(s, index));
225 return InternalGetDecimalDigitValue(ch);
242 if (index < 0 || index >= s.Length)
246 return InternalGetDecimalDigitValue(InternalConvertToUtf32(s, index));
254 return InternalGetDigitValue(ch);
271 if (index < 0 || index >= s.Length)
275 return InternalGetDigitValue(InternalConvertToUtf32(s, index));
281 [__DynamicallyInvokable]
284 return InternalGetUnicodeCategory(ch);
295 [__DynamicallyInvokable]
302 if ((uint)index >= (uint)s.Length)
306 return InternalGetUnicodeCategory(s, index);
314 [SecuritySafeCritical]
315 internal unsafe
static byte InternalGetCategoryValue(
int ch,
int offset)
317 ushort num = s_pCategoryLevel1Index[ch >> 8];
318 num = s_pCategoryLevel1Index[num + ((ch >> 4) & 0xF)];
319 byte* ptr = (
byte*)(s_pCategoryLevel1Index + (
int)num);
320 byte b = ptr[ch & 0xF];
321 return s_pCategoriesValue[b * 2 + offset];
324 internal static BidiCategory GetBidiCategory(
string s,
int index)
328 throw new ArgumentNullException(
"s");
330 if ((uint)index >= (uint)s.Length)
332 throw new ArgumentOutOfRangeException(
"index");
334 return (BidiCategory)InternalGetCategoryValue(InternalConvertToUtf32(s, index), 1);
337 internal static UnicodeCategory InternalGetUnicodeCategory(
string value,
int index)
339 return InternalGetUnicodeCategory(InternalConvertToUtf32(value, index));
342 internal static UnicodeCategory InternalGetUnicodeCategory(
string str,
int index, out
int charLength)
344 return InternalGetUnicodeCategory(InternalConvertToUtf32(str, index, out charLength));
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static int GetDigitValue(string s, int index)
Gets the digit value of the numeric character at the specified index of the specified string.
LayoutKind
Controls the layout of an object when exported to unmanaged code.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static UnicodeCategory GetUnicodeCategory(string s, int index)
Gets the Unicode category of the character at the specified index of the specified string.
static int GetDecimalDigitValue(char ch)
Gets the decimal digit value of the specified numeric character.
Provides information about, and means to manipulate, the current environment and platform....
static UnicodeCategory GetUnicodeCategory(char ch)
Gets the Unicode category of the specified character.
static int GetDecimalDigitValue(string s, int index)
Gets the decimal digit value of the numeric character at the specified index of the specified string.
static int GetDigitValue(char ch)
Gets the digit value of the specified numeric character.
Attribute can be applied to an assembly.
Retrieves information about a Unicode character. This class cannot be inherited.
UnicodeCategory
Defines the Unicode category of a character.
static double GetNumericValue(char ch)
Gets the numeric value associated with the specified character.
static double GetNumericValue(string s, int index)
Gets the numeric value associated with the character at the specified index of the specified string.
Manipulates arrays of primitive types.