Exemplo n.º 1
0
 private static bool CanBePrimaryComposite(int i)
 {
     if (i >= 13312 && i <= 40891)
     {
         return(Normalization.GetPrimaryCompositeHelperIndex(i) != 0);
     }
     return((Normalization.PropValue(i) & 128u) != 0u);
 }
Exemplo n.º 2
0
 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;
             }
         }
     }
 }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
0
 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;
     }
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        unsafe static Normalization()
        {
            object obj = Normalization.forLock;

            lock (obj)
            {
                IntPtr value;
                IntPtr value2;
                IntPtr value3;
                IntPtr value4;
                IntPtr value5;
                IntPtr value6;
                Normalization.load_normalization_resource(out value, out value2, out value3, out value4, out value5, out value6);
                Normalization.props             = (byte *)((void *)value);
                Normalization.mappedChars       = (int *)((void *)value2);
                Normalization.charMapIndex      = (short *)((void *)value3);
                Normalization.helperIndex       = (short *)((void *)value4);
                Normalization.mapIdxToComposite = (ushort *)((void *)value5);
                Normalization.combiningClass    = (byte *)((void *)value6);
            }
            Normalization.isReady = true;
        }
Exemplo n.º 11
0
        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);
        }