573 lines
15 KiB
C#
573 lines
15 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
|
|
namespace Mono.Globalization.Unicode
|
|
{
|
|
// Token: 0x02000088 RID: 136
|
|
internal class Normalization
|
|
{
|
|
// Token: 0x060007B5 RID: 1973 RVA: 0x000191E0 File Offset: 0x000173E0
|
|
unsafe static Normalization()
|
|
{
|
|
object obj = Normalization.forLock;
|
|
lock (obj)
|
|
{
|
|
IntPtr intPtr;
|
|
IntPtr intPtr2;
|
|
IntPtr intPtr3;
|
|
IntPtr intPtr4;
|
|
IntPtr intPtr5;
|
|
IntPtr intPtr6;
|
|
Normalization.load_normalization_resource(out intPtr, out intPtr2, out intPtr3, out intPtr4, out intPtr5, out intPtr6);
|
|
Normalization.props = (byte*)(void*)intPtr;
|
|
Normalization.mappedChars = (int*)(void*)intPtr2;
|
|
Normalization.charMapIndex = (short*)(void*)intPtr3;
|
|
Normalization.helperIndex = (short*)(void*)intPtr4;
|
|
Normalization.mapIdxToComposite = (ushort*)(void*)intPtr5;
|
|
Normalization.combiningClass = (byte*)(void*)intPtr6;
|
|
}
|
|
Normalization.isReady = true;
|
|
}
|
|
|
|
// Token: 0x060007B6 RID: 1974 RVA: 0x0001928C File Offset: 0x0001748C
|
|
private unsafe static uint PropValue(int cp)
|
|
{
|
|
return (uint)Normalization.props[NormalizationTableUtil.PropIdx(cp)];
|
|
}
|
|
|
|
// Token: 0x060007B7 RID: 1975 RVA: 0x0001929C File Offset: 0x0001749C
|
|
private unsafe static int CharMapIdx(int cp)
|
|
{
|
|
return (int)Normalization.charMapIndex[NormalizationTableUtil.MapIdx(cp)];
|
|
}
|
|
|
|
// Token: 0x060007B8 RID: 1976 RVA: 0x000192B0 File Offset: 0x000174B0
|
|
private unsafe static int GetNormalizedStringLength(int ch)
|
|
{
|
|
int num = (int)Normalization.charMapIndex[NormalizationTableUtil.MapIdx(ch)];
|
|
int num2 = num;
|
|
while (Normalization.mappedChars[num2] != 0)
|
|
{
|
|
num2++;
|
|
}
|
|
return num2 - num;
|
|
}
|
|
|
|
// Token: 0x060007B9 RID: 1977 RVA: 0x000192EC File Offset: 0x000174EC
|
|
private unsafe static byte GetCombiningClass(int c)
|
|
{
|
|
return Normalization.combiningClass[NormalizationTableUtil.Combining.ToIndex(c)];
|
|
}
|
|
|
|
// Token: 0x060007BA RID: 1978 RVA: 0x00019300 File Offset: 0x00017500
|
|
private unsafe static int GetPrimaryCompositeFromMapIndex(int src)
|
|
{
|
|
return (int)Normalization.mapIdxToComposite[NormalizationTableUtil.Composite.ToIndex(src)];
|
|
}
|
|
|
|
// Token: 0x060007BB RID: 1979 RVA: 0x00019318 File Offset: 0x00017518
|
|
private unsafe static int GetPrimaryCompositeHelperIndex(int cp)
|
|
{
|
|
return (int)Normalization.helperIndex[NormalizationTableUtil.Helper.ToIndex(cp)];
|
|
}
|
|
|
|
// Token: 0x060007BC RID: 1980 RVA: 0x00019330 File Offset: 0x00017530
|
|
private unsafe static int GetPrimaryCompositeCharIndex(object chars, int start)
|
|
{
|
|
string text = chars as string;
|
|
StringBuilder stringBuilder = chars as StringBuilder;
|
|
char c = ((text == null) ? stringBuilder[start] : text[start]);
|
|
int num = ((stringBuilder == null) ? text.Length : stringBuilder.Length);
|
|
int num2 = Normalization.GetPrimaryCompositeHelperIndex((int)c);
|
|
if (num2 == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
while (Normalization.mappedChars[num2] == (int)c)
|
|
{
|
|
int num3 = 0;
|
|
int num4 = 1;
|
|
int num5 = 1;
|
|
for (;;)
|
|
{
|
|
int num6 = num3;
|
|
if (Normalization.mappedChars[num2 + num4] == 0)
|
|
{
|
|
return num2;
|
|
}
|
|
if (start + num4 >= num)
|
|
{
|
|
return 0;
|
|
}
|
|
bool flag = false;
|
|
char c2;
|
|
do
|
|
{
|
|
c2 = ((text == null) ? stringBuilder[start + num5] : text[start + num5]);
|
|
num3 = (int)Normalization.GetCombiningClass((int)c2);
|
|
if (Normalization.mappedChars[num2 + num4] == (int)c2)
|
|
{
|
|
goto Block_7;
|
|
}
|
|
if (num3 < num6)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
while (++num5 + start < num && num3 != 0);
|
|
IL_105:
|
|
if (!flag)
|
|
{
|
|
if (num6 >= num3)
|
|
{
|
|
break;
|
|
}
|
|
num5--;
|
|
if (Normalization.mappedChars[num2 + num4] != (int)c2)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
num4++;
|
|
num5++;
|
|
continue;
|
|
Block_7:
|
|
flag = true;
|
|
goto IL_105;
|
|
}
|
|
while (Normalization.mappedChars[num4] != 0)
|
|
{
|
|
num4++;
|
|
}
|
|
num2 += num4 + 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// Token: 0x060007BD RID: 1981 RVA: 0x000194C4 File Offset: 0x000176C4
|
|
private static string Compose(string source, int checkType)
|
|
{
|
|
StringBuilder stringBuilder = null;
|
|
Normalization.Decompose(source, ref stringBuilder, checkType);
|
|
if (stringBuilder == null)
|
|
{
|
|
stringBuilder = Normalization.Combine(source, 0, checkType);
|
|
}
|
|
else
|
|
{
|
|
Normalization.Combine(stringBuilder, 0, checkType);
|
|
}
|
|
return (stringBuilder == null) ? source : stringBuilder.ToString();
|
|
}
|
|
|
|
// Token: 0x060007BE RID: 1982 RVA: 0x0001950C File Offset: 0x0001770C
|
|
private static StringBuilder Combine(string source, int start, int checkType)
|
|
{
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
if (Normalization.QuickCheck(source[i], checkType) != NormalizationCheck.Yes)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder(source.Length + source.Length / 10);
|
|
stringBuilder.Append(source);
|
|
Normalization.Combine(stringBuilder, i, checkType);
|
|
return stringBuilder;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Token: 0x060007BF RID: 1983 RVA: 0x00019570 File Offset: 0x00017770
|
|
private static bool CanBePrimaryComposite(int i)
|
|
{
|
|
if (i >= 13312 && i <= 40891)
|
|
{
|
|
return Normalization.GetPrimaryCompositeHelperIndex(i) != 0;
|
|
}
|
|
return (Normalization.PropValue(i) & 128U) != 0U;
|
|
}
|
|
|
|
// Token: 0x060007C0 RID: 1984 RVA: 0x000195A8 File Offset: 0x000177A8
|
|
private unsafe static void Combine(StringBuilder sb, int start, int checkType)
|
|
{
|
|
for (int i = start; i < sb.Length; i++)
|
|
{
|
|
if (Normalization.QuickCheck(sb[i], checkType) != NormalizationCheck.Yes)
|
|
{
|
|
int num = i;
|
|
while (i > 0)
|
|
{
|
|
if (Normalization.GetCombiningClass((int)sb[i]) == 0)
|
|
{
|
|
break;
|
|
}
|
|
i--;
|
|
}
|
|
int num2 = 0;
|
|
while (i < num)
|
|
{
|
|
num2 = Normalization.GetPrimaryCompositeMapIndex(sb, (int)sb[i], i);
|
|
if (num2 > 0)
|
|
{
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
if (num2 == 0)
|
|
{
|
|
i = num;
|
|
}
|
|
else
|
|
{
|
|
int primaryCompositeFromMapIndex = Normalization.GetPrimaryCompositeFromMapIndex(num2);
|
|
int normalizedStringLength = Normalization.GetNormalizedStringLength(primaryCompositeFromMapIndex);
|
|
if (primaryCompositeFromMapIndex == 0 || normalizedStringLength == 0)
|
|
{
|
|
throw new SystemException("Internal error: should not happen. Input: " + sb);
|
|
}
|
|
int j = 0;
|
|
sb.Insert(i++, (char)primaryCompositeFromMapIndex);
|
|
while (j < normalizedStringLength)
|
|
{
|
|
if ((int)sb[i] == Normalization.mappedChars[num2 + j])
|
|
{
|
|
sb.Remove(i, 1);
|
|
j++;
|
|
}
|
|
else
|
|
{
|
|
i++;
|
|
}
|
|
}
|
|
i = num - 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060007C1 RID: 1985 RVA: 0x000196C8 File Offset: 0x000178C8
|
|
private static int GetPrimaryCompositeMapIndex(object o, int cur, int bufferPos)
|
|
{
|
|
if ((Normalization.PropValue(cur) & 64U) != 0U)
|
|
{
|
|
return 0;
|
|
}
|
|
if (Normalization.GetCombiningClass(cur) != 0)
|
|
{
|
|
return 0;
|
|
}
|
|
return Normalization.GetPrimaryCompositeCharIndex(o, bufferPos);
|
|
}
|
|
|
|
// Token: 0x060007C2 RID: 1986 RVA: 0x000196FC File Offset: 0x000178FC
|
|
private static string Decompose(string source, int checkType)
|
|
{
|
|
StringBuilder stringBuilder = null;
|
|
Normalization.Decompose(source, ref stringBuilder, checkType);
|
|
return (stringBuilder == null) ? source : stringBuilder.ToString();
|
|
}
|
|
|
|
// Token: 0x060007C3 RID: 1987 RVA: 0x00019728 File Offset: 0x00017928
|
|
private static void Decompose(string source, ref StringBuilder sb, int checkType)
|
|
{
|
|
int[] array = null;
|
|
int num = 0;
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
if (Normalization.QuickCheck(source[i], checkType) == NormalizationCheck.No)
|
|
{
|
|
Normalization.DecomposeChar(ref sb, ref array, source, i, ref num);
|
|
}
|
|
}
|
|
if (sb != null)
|
|
{
|
|
sb.Append(source, num, source.Length - num);
|
|
}
|
|
Normalization.ReorderCanonical(source, ref sb, 1);
|
|
}
|
|
|
|
// Token: 0x060007C4 RID: 1988 RVA: 0x00019790 File Offset: 0x00017990
|
|
private static void ReorderCanonical(string src, ref StringBuilder sb, int start)
|
|
{
|
|
if (sb == null)
|
|
{
|
|
for (int i = 1; i < src.Length; i++)
|
|
{
|
|
int num = (int)Normalization.GetCombiningClass((int)src[i]);
|
|
if (num != 0)
|
|
{
|
|
if ((int)Normalization.GetCombiningClass((int)src[i - 1]) > num)
|
|
{
|
|
sb = new StringBuilder(src.Length);
|
|
sb.Append(src, 0, src.Length);
|
|
Normalization.ReorderCanonical(src, ref sb, i);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
for (int j = start; j < sb.Length; j++)
|
|
{
|
|
int num2 = (int)Normalization.GetCombiningClass((int)sb[j]);
|
|
if (num2 != 0)
|
|
{
|
|
if ((int)Normalization.GetCombiningClass((int)sb[j - 1]) > num2)
|
|
{
|
|
char c = sb[j - 1];
|
|
sb[j - 1] = sb[j];
|
|
sb[j] = c;
|
|
j--;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060007C5 RID: 1989 RVA: 0x00019880 File Offset: 0x00017A80
|
|
private static void DecomposeChar(ref StringBuilder sb, ref int[] buf, string s, int i, ref int start)
|
|
{
|
|
if (sb == null)
|
|
{
|
|
sb = new StringBuilder(s.Length + 100);
|
|
}
|
|
sb.Append(s, start, i - start);
|
|
if (buf == null)
|
|
{
|
|
buf = new int[19];
|
|
}
|
|
Normalization.GetCanonical((int)s[i], buf, 0);
|
|
int num = 0;
|
|
while (buf[num] != 0)
|
|
{
|
|
if (buf[num] < 65535)
|
|
{
|
|
sb.Append((char)buf[num]);
|
|
}
|
|
else
|
|
{
|
|
sb.Append((char)(buf[num] >> 10));
|
|
sb.Append((char)((buf[num] & 4095) + 56320));
|
|
}
|
|
num++;
|
|
}
|
|
start = i + 1;
|
|
}
|
|
|
|
// Token: 0x060007C6 RID: 1990 RVA: 0x00019944 File Offset: 0x00017B44
|
|
public static NormalizationCheck QuickCheck(char c, int type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case 1:
|
|
if ('가' <= c && c <= '힣')
|
|
{
|
|
return NormalizationCheck.No;
|
|
}
|
|
return ((Normalization.PropValue((int)c) & 1U) == 0U) ? NormalizationCheck.Yes : NormalizationCheck.No;
|
|
case 2:
|
|
{
|
|
uint num = Normalization.PropValue((int)c);
|
|
return ((num & 16U) == 0U) ? (((num & 32U) == 0U) ? NormalizationCheck.Yes : NormalizationCheck.Maybe) : NormalizationCheck.No;
|
|
}
|
|
case 3:
|
|
if ('가' <= c && c <= '힣')
|
|
{
|
|
return NormalizationCheck.No;
|
|
}
|
|
return ((Normalization.PropValue((int)c) & 2U) == 0U) ? NormalizationCheck.Yes : NormalizationCheck.No;
|
|
default:
|
|
{
|
|
uint num = Normalization.PropValue((int)c);
|
|
return ((num & 4U) != 0U) ? NormalizationCheck.No : (((num & 8U) != 0U) ? NormalizationCheck.Maybe : NormalizationCheck.Yes);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060007C7 RID: 1991 RVA: 0x00019A14 File Offset: 0x00017C14
|
|
private static bool GetCanonicalHangul(int s, int[] buf, int bufIdx)
|
|
{
|
|
int num = s - 44032;
|
|
if (num < 0 || num >= 11172)
|
|
{
|
|
return false;
|
|
}
|
|
int num2 = 4352 + num / 588;
|
|
int num3 = 4449 + num % 588 / 28;
|
|
int num4 = 4519 + num % 28;
|
|
buf[bufIdx++] = num2;
|
|
buf[bufIdx++] = num3;
|
|
if (num4 != 4519)
|
|
{
|
|
buf[bufIdx++] = num4;
|
|
}
|
|
buf[bufIdx] = 0;
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x060007C8 RID: 1992 RVA: 0x00019A94 File Offset: 0x00017C94
|
|
public unsafe static void GetCanonical(int c, int[] buf, int bufIdx)
|
|
{
|
|
if (!Normalization.GetCanonicalHangul(c, buf, bufIdx))
|
|
{
|
|
int num = Normalization.CharMapIdx(c);
|
|
while (Normalization.mappedChars[num] != 0)
|
|
{
|
|
buf[bufIdx++] = Normalization.mappedChars[num];
|
|
num++;
|
|
}
|
|
buf[bufIdx] = 0;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060007C9 RID: 1993 RVA: 0x00019AE4 File Offset: 0x00017CE4
|
|
public static bool IsNormalized(string source, int type)
|
|
{
|
|
int num = -1;
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
int num2 = (int)Normalization.GetCombiningClass((int)source[i]);
|
|
if (num2 != 0 && num2 < num)
|
|
{
|
|
return false;
|
|
}
|
|
num = num2;
|
|
switch (Normalization.QuickCheck(source[i], type))
|
|
{
|
|
case NormalizationCheck.No:
|
|
return false;
|
|
case NormalizationCheck.Maybe:
|
|
{
|
|
switch (type)
|
|
{
|
|
case 0:
|
|
case 2:
|
|
return source == Normalization.Normalize(source, type);
|
|
}
|
|
int num3 = i;
|
|
while (i > 0)
|
|
{
|
|
if (Normalization.GetCombiningClass((int)source[i]) == 0)
|
|
{
|
|
break;
|
|
}
|
|
i--;
|
|
}
|
|
while (i < num3)
|
|
{
|
|
if (Normalization.GetPrimaryCompositeCharIndex(source, i) != 0)
|
|
{
|
|
return false;
|
|
}
|
|
i++;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x060007CA RID: 1994 RVA: 0x00019BCC File Offset: 0x00017DCC
|
|
public static string Normalize(string source, int type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case 1:
|
|
case 3:
|
|
return Normalization.Decompose(source, type);
|
|
default:
|
|
return Normalization.Compose(source, type);
|
|
}
|
|
}
|
|
|
|
// Token: 0x170000DD RID: 221
|
|
// (get) Token: 0x060007CB RID: 1995 RVA: 0x00019C04 File Offset: 0x00017E04
|
|
public static bool IsReady
|
|
{
|
|
get
|
|
{
|
|
return Normalization.isReady;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060007CC RID: 1996
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern void load_normalization_resource(out IntPtr props, out IntPtr mappedChars, out IntPtr charMapIndex, out IntPtr helperIndex, out IntPtr mapIdxToComposite, out IntPtr combiningClass);
|
|
|
|
// Token: 0x0400014D RID: 333
|
|
public const int NoNfd = 1;
|
|
|
|
// Token: 0x0400014E RID: 334
|
|
public const int NoNfkd = 2;
|
|
|
|
// Token: 0x0400014F RID: 335
|
|
public const int NoNfc = 4;
|
|
|
|
// Token: 0x04000150 RID: 336
|
|
public const int MaybeNfc = 8;
|
|
|
|
// Token: 0x04000151 RID: 337
|
|
public const int NoNfkc = 16;
|
|
|
|
// Token: 0x04000152 RID: 338
|
|
public const int MaybeNfkc = 32;
|
|
|
|
// Token: 0x04000153 RID: 339
|
|
public const int FullCompositionExclusion = 64;
|
|
|
|
// Token: 0x04000154 RID: 340
|
|
public const int IsUnsafe = 128;
|
|
|
|
// Token: 0x04000155 RID: 341
|
|
private const int HangulSBase = 44032;
|
|
|
|
// Token: 0x04000156 RID: 342
|
|
private const int HangulLBase = 4352;
|
|
|
|
// Token: 0x04000157 RID: 343
|
|
private const int HangulVBase = 4449;
|
|
|
|
// Token: 0x04000158 RID: 344
|
|
private const int HangulTBase = 4519;
|
|
|
|
// Token: 0x04000159 RID: 345
|
|
private const int HangulLCount = 19;
|
|
|
|
// Token: 0x0400015A RID: 346
|
|
private const int HangulVCount = 21;
|
|
|
|
// Token: 0x0400015B RID: 347
|
|
private const int HangulTCount = 28;
|
|
|
|
// Token: 0x0400015C RID: 348
|
|
private const int HangulNCount = 588;
|
|
|
|
// Token: 0x0400015D RID: 349
|
|
private const int HangulSCount = 11172;
|
|
|
|
// Token: 0x0400015E RID: 350
|
|
private unsafe static byte* props;
|
|
|
|
// Token: 0x0400015F RID: 351
|
|
private unsafe static int* mappedChars;
|
|
|
|
// Token: 0x04000160 RID: 352
|
|
private unsafe static short* charMapIndex;
|
|
|
|
// Token: 0x04000161 RID: 353
|
|
private unsafe static short* helperIndex;
|
|
|
|
// Token: 0x04000162 RID: 354
|
|
private unsafe static ushort* mapIdxToComposite;
|
|
|
|
// Token: 0x04000163 RID: 355
|
|
private unsafe static byte* combiningClass;
|
|
|
|
// Token: 0x04000164 RID: 356
|
|
private static object forLock = new object();
|
|
|
|
// Token: 0x04000165 RID: 357
|
|
public static readonly bool isReady;
|
|
}
|
|
}
|