static MSCompatUnicodeTable ()
    {
#if USE_C_HEADER
        byte* raw;
        uint* tailor;
        uint size;
        uint idx = 0;

        lock (forLock)
        {
            load_collation_resource (CollationTableIdxIgnorables, &raw);
            ignorableFlags = raw;
            load_collation_resource (CollationTableIdxCategory, &raw);
            categories = raw;
            load_collation_resource (CollationTableIdxLevel1, &raw);
            level1 = raw;
            load_collation_resource (CollationTableIdxLevel2, &raw);
            level2 = raw;
            load_collation_resource (CollationTableIdxLevel3, &raw);
            level3 = raw;
            load_collation_resource (CollationTableIdxTailoringInfos, &raw);
            tailor = (uint*) raw;
            load_collation_resource (CollationTableIdxTailoringChars, &raw);
            tailoring = (char*) raw;
        }

        idx = 0;
        uint count = tailor [idx++];
        tailoringInfos = new TailoringInfo [count];
        for (int i = 0; i < count; i++)
        {
            int i1 = (int) tailor [idx++];
            int i2 = (int) tailor [idx++];
            int i3 = (int) tailor [idx++];
            TailoringInfo ti = new TailoringInfo (
                i1, i2, i3, tailor [idx++] != 0);
            tailoringInfos [i] = ti;
        }

        isReady = true;
#else

        byte* raw;
        byte* tailor;
        uint size;
        uint idx = 0;

#if USE_MANAGED_RESOURCE
        IntPtr ptr = GetResource ("collation.core.bin");
        if (ptr == IntPtr.Zero)
            return;
        raw = (byte*) ((void*) ptr);
        ptr = GetResource ("collation.tailoring.bin");
        if (ptr == IntPtr.Zero)
            return;
        tailor = (byte*) ((void*) ptr);
#else
        int rawsize;
        int trawsize;

        lock (forLock)
        {
            load_collation_resource (corlibPath, CollationResourceCore, &raw, &rawsize);
            load_collation_resource (corlibPath, CollationResourceTailoring, &tailor, &trawsize);
            load_collation_resource (corlibPath, CollationResourceTailoringChars, &tailorChars, &trawsize);
        }
#endif

        if (raw == null || tailor == null)
            return;
        // check resource version
        if (raw [0] != UUtil.ResourceVersion ||
                tailor [0] != UUtil.ResourceVersion)
            return;

        idx = 1;
        size = UInt32FromBytePtr (raw, idx);
        idx += 4;
        ignorableFlags = raw + idx;
        idx += size;

        size = UInt32FromBytePtr (raw, idx);
        idx += 4;
        categories = raw + idx;
        idx += size;

        size = UInt32FromBytePtr (raw, idx);
        idx += 4;
        level1 = raw + idx;
        idx += size;

        size = UInt32FromBytePtr (raw, idx);
        idx += 4;
        level2 = raw + idx;
        idx += size;

        size = UInt32FromBytePtr (raw, idx);
        idx += 4;
        level3 = raw + idx;
        idx += size;

//			size = UInt32FromBytePtr (raw, idx);
//			idx += 4;
//			widthCompat = (ushort*) (raw + idx);
//			idx += size * 2;

        // tailoring

        idx = 1;
        uint count = UInt32FromBytePtr (tailor, idx);
        idx += 4;
        tailoringInfos = new TailoringInfo [count];
        for (int i = 0; i < count; i++)
        {
            int i1 = (int) UInt32FromBytePtr (tailor, idx);
            idx += 4;
            int i2 = (int) UInt32FromBytePtr (tailor, idx);
            idx += 4;
            int i3 = (int) UInt32FromBytePtr (tailor, idx);
            idx += 4;
            TailoringInfo ti = new TailoringInfo (
                i1, i2, i3, tailor [idx++] != 0);
            tailoringInfos [i] = ti;
        }
        idx += 2; // dummy
        // tailorings
        count = UInt32FromBytePtr (tailor, idx);
        idx += 4;

        tailoringArr = new char [count];
        for (int i = 0; i < count; i++, idx += 2)
            tailoringArr [i] = (char) (tailor [idx] + (tailor [idx + 1] << 8));
        isReady = true;
#endif
    }
 unsafe public static void BuildTailoringTables (CultureInfo culture,
         TailoringInfo t,
         ref Contraction [] contractions,
         ref Level2Map [] diacriticals)
 {
     // collect tailoring entries.
     ArrayList cmaps = new ArrayList ();
     ArrayList dmaps = new ArrayList ();
     fixed (char* tarr = tailoringArr)
     {
         int idx = t.TailoringIndex;
         int end = idx + t.TailoringCount;
         while (idx < end)
         {
             int ss = idx + 1;
             char [] src = null;
             switch (tarr [idx])
             {
             case '\x1': // SortKeyMap
                 idx++;
                 while (tarr [ss] != 0)
                     ss++;
                 src = new char [ss - idx];
                 //					Array.Copy (tarr, idx, src, 0, ss - idx);
                 Marshal.Copy ((IntPtr) (tarr + idx), src, 0, ss - idx);
                 byte [] sortkey = new byte [4];
                 for (int i = 0; i < 4; i++)
                     sortkey [i] = (byte) tarr [ss + 1 + i];
                 cmaps.Add (new Contraction (
                                src, null, sortkey));
                 // it ends with 0
                 idx = ss + 6;
                 break;
             case '\x2': // DiacriticalMap
                 dmaps.Add (new Level2Map (
                                (byte) tarr [idx + 1],
                                (byte) tarr [idx + 2]));
                 idx += 3;
                 break;
             case '\x3': // ReplacementMap
                 idx++;
                 while (tarr [ss] != 0)
                     ss++;
                 src = new char [ss - idx];
                 //					Array.Copy (tarr, idx, src, 0, ss - idx);
                 Marshal.Copy ((IntPtr) (tarr + idx), src, 0, ss - idx);
                 ss++;
                 int l = ss;
                 while (tarr [l] != 0)
                     l++;
                 string r = new string (tarr, ss, l - ss);
                 cmaps.Add (new Contraction (
                                src, r, null));
                 idx = l + 1;
                 break;
             default:
                 throw new NotImplementedException (String.Format ("Mono INTERNAL ERROR (Should not happen): Collation tailoring table is broken for culture {0} ({1}) at 0x{2:X}", culture.LCID, culture.Name, idx));
             }
         }
     }
     cmaps.Sort (ContractionComparer.Instance);
     dmaps.Sort (Level2MapComparer.Instance);
     contractions = cmaps.ToArray (typeof (Contraction))
                    as Contraction [];
     diacriticals = dmaps.ToArray (typeof (Level2Map))
                    as Level2Map [];
 }
Esempio n. 3
0
		unsafe public static void BuildTailoringTables (CultureInfo culture,
			TailoringInfo t,
			ref Contraction [] contractions,
			ref Level2Map [] diacriticals)
		{
			// collect tailoring entries.
			ArrayList cmaps = new ArrayList ();
			ArrayList dmaps = new ArrayList ();
			fixed (char* tarr = tailoringArr){
				int idx = t.TailoringIndex;
				int end = idx + t.TailoringCount;
				while (idx < end) {
					int ss = idx + 1;
					char [] src = null;
					switch (tarr [idx]) {
					case '\x1': // SortKeyMap
						idx++;
						while (tarr [ss] != 0)
							ss++;
						src = new char [ss - idx];
						//					Array.Copy (tarr, idx, src, 0, ss - idx);
						Marshal.Copy ((IntPtr) (tarr + idx), src, 0, ss - idx);
						byte [] sortkey = new byte [4];
						for (int i = 0; i < 4; i++)
							sortkey [i] = (byte) tarr [ss + 1 + i];
						cmaps.Add (new Contraction (
									    src, null, sortkey));
						// it ends with 0
						idx = ss + 6;
						break;
					case '\x2': // DiacriticalMap
						dmaps.Add (new Level2Map (
									  (byte) tarr [idx + 1],
									  (byte) tarr [idx + 2]));
						idx += 3;
						break;
					case '\x3': // ReplacementMap
						idx++;
						while (tarr [ss] != 0)
							ss++;
						src = new char [ss - idx];
						//					Array.Copy (tarr, idx, src, 0, ss - idx);
						Marshal.Copy ((IntPtr) (tarr + idx), src, 0, ss - idx);
						ss++;
						int l = ss;
						while (tarr [l] != 0)
							l++;
						string r = new string (tarr, ss, l - ss);
						cmaps.Add (new Contraction (
									    src, r, null));
						idx = l + 1;
						break;
					default:
						throw new NotImplementedException (String.Format ("Mono INTERNAL ERROR (Should not happen): Collation tailoring table is broken for culture {0} ({1}) at 0x{2:X}", culture.LCID, culture.Name, idx));
					}
				}
			}
			cmaps.Sort (ContractionComparer.Instance);
			dmaps.Sort (Level2MapComparer.Instance);
			contractions = cmaps.ToArray (typeof (Contraction))
				as Contraction [];
			diacriticals = dmaps.ToArray (typeof (Level2Map))
				as Level2Map [];
		}
        unsafe static MSCompatUnicodeTable()
        {
            IntPtr resource = MSCompatUnicodeTable.GetResource("collation.core.bin");

            if (resource == IntPtr.Zero)
            {
                return;
            }
            byte *ptr = (byte *)((void *)resource);

            resource = MSCompatUnicodeTable.GetResource("collation.tailoring.bin");
            if (resource == IntPtr.Zero)
            {
                return;
            }
            byte *ptr2 = (byte *)((void *)resource);

            if (ptr == null || ptr2 == null)
            {
                return;
            }
            if (*ptr != 3 || *ptr2 != 3)
            {
                return;
            }
            uint num  = 1u;
            uint num2 = MSCompatUnicodeTable.UInt32FromBytePtr(ptr, num);

            num += 4u;
            MSCompatUnicodeTable.ignorableFlags = ptr + num;
            num += num2;
            num2 = MSCompatUnicodeTable.UInt32FromBytePtr(ptr, num);
            num += 4u;
            MSCompatUnicodeTable.categories = ptr + num;
            num += num2;
            num2 = MSCompatUnicodeTable.UInt32FromBytePtr(ptr, num);
            num += 4u;
            MSCompatUnicodeTable.level1 = ptr + num;
            num += num2;
            num2 = MSCompatUnicodeTable.UInt32FromBytePtr(ptr, num);
            num += 4u;
            MSCompatUnicodeTable.level2 = ptr + num;
            num += num2;
            num2 = MSCompatUnicodeTable.UInt32FromBytePtr(ptr, num);
            num += 4u;
            MSCompatUnicodeTable.level3 = ptr + num;
            num += num2;
            num  = 1u;
            uint num3 = MSCompatUnicodeTable.UInt32FromBytePtr(ptr2, num);

            num += 4u;
            MSCompatUnicodeTable.tailoringInfos = new TailoringInfo[num3];
            int num4 = 0;

            while ((long)num4 < (long)((ulong)num3))
            {
                int lcid = (int)MSCompatUnicodeTable.UInt32FromBytePtr(ptr2, num);
                num += 4u;
                int tailoringIndex = (int)MSCompatUnicodeTable.UInt32FromBytePtr(ptr2, num);
                num += 4u;
                int tailoringCount = (int)MSCompatUnicodeTable.UInt32FromBytePtr(ptr2, num);
                num += 4u;
                TailoringInfo tailoringInfo = new TailoringInfo(lcid, tailoringIndex, tailoringCount, ptr2[(UIntPtr)(num++)] != 0);
                MSCompatUnicodeTable.tailoringInfos[num4] = tailoringInfo;
                num4++;
            }
            num += 2u;
            num3 = MSCompatUnicodeTable.UInt32FromBytePtr(ptr2, num);
            num += 4u;
            MSCompatUnicodeTable.tailoringArr = new char[num3];
            int num5 = 0;

            while ((long)num5 < (long)((ulong)num3))
            {
                MSCompatUnicodeTable.tailoringArr[num5] = (char)((int)ptr2[num] + ((int)ptr2[num + 1u] << 8));
                num5++;
                num += 2u;
            }
            MSCompatUnicodeTable.isReady = true;
        }
        public unsafe static void BuildTailoringTables(CultureInfo culture, TailoringInfo t, ref Contraction[] contractions, ref Level2Map[] diacriticals)
        {
            ArrayList arrayList  = new ArrayList();
            ArrayList arrayList2 = new ArrayList();

            fixed(char *ptr = ref (MSCompatUnicodeTable.tailoringArr != null && MSCompatUnicodeTable.tailoringArr.Length != 0)?ref MSCompatUnicodeTable.tailoringArr[0] : ref *null)
            {
                int i   = t.TailoringIndex;
                int num = i + t.TailoringCount;

                while (i < num)
                {
                    int num2 = i + 1;
                    switch (ptr[i])
                    {
                    case '\u0001':
                    {
                        i++;
                        while (ptr[num2] != '\0')
                        {
                            num2++;
                        }
                        char[] array = new char[num2 - i];
                        Marshal.Copy((IntPtr)((void *)(ptr + i)), array, 0, num2 - i);
                        byte[] array2 = new byte[4];
                        for (int j = 0; j < 4; j++)
                        {
                            array2[j] = (byte)ptr[num2 + 1 + j];
                        }
                        arrayList.Add(new Contraction(array, null, array2));
                        i = num2 + 6;
                        break;
                    }

                    case '\u0002':
                        arrayList2.Add(new Level2Map((byte)ptr[i + 1], (byte)ptr[i + 2]));
                        i += 3;
                        break;

                    case '\u0003':
                    {
                        i++;
                        while (ptr[num2] != '\0')
                        {
                            num2++;
                        }
                        char[] array = new char[num2 - i];
                        Marshal.Copy((IntPtr)((void *)(ptr + i)), array, 0, num2 - i);
                        num2++;
                        int num3 = num2;
                        while (ptr[num3] != '\0')
                        {
                            num3++;
                        }
                        string replacement = new string(ptr, num2, num3 - num2);
                        arrayList.Add(new Contraction(array, replacement, null));
                        i = num3 + 1;
                        break;
                    }

                    default:
                        throw new NotImplementedException(string.Format("Mono INTERNAL ERROR (Should not happen): Collation tailoring table is broken for culture {0} ({1}) at 0x{2:X}", culture.LCID, culture.Name, i));
                    }
                }
            }

            arrayList.Sort(ContractionComparer.Instance);
            arrayList2.Sort(Level2MapComparer.Instance);
            contractions = (arrayList.ToArray(typeof(Contraction)) as Contraction[]);
            diacriticals = (arrayList2.ToArray(typeof(Level2Map)) as Level2Map[]);
        }
		static MSCompatUnicodeTable ()
		{
#if USE_C_HEADER
			byte* raw;
			uint* tailor;
			uint size;
			uint idx = 0;

			lock (forLock) {
				load_collation_resource (CollationTableIdxIgnorables, &raw);
				ignorableFlags = raw;
				load_collation_resource (CollationTableIdxCategory, &raw);
				categories = raw;
				load_collation_resource (CollationTableIdxLevel1, &raw);
				level1 = raw;
				load_collation_resource (CollationTableIdxLevel2, &raw);
				level2 = raw;
				load_collation_resource (CollationTableIdxLevel3, &raw);
				level3 = raw;
				load_collation_resource (CollationTableIdxTailoringInfos, &raw);
				tailor = (uint*) raw;
				load_collation_resource (CollationTableIdxTailoringChars, &raw);
				tailoring = (char*) raw;
			}

			idx = 0;
			uint count = tailor [idx++];
			tailoringInfos = new TailoringInfo [count];
			for (int i = 0; i < count; i++) {
				int i1 = (int) tailor [idx++];
				int i2 = (int) tailor [idx++];
				int i3 = (int) tailor [idx++];
				TailoringInfo ti = new TailoringInfo (
					i1, i2, i3, tailor [idx++] != 0);
				tailoringInfos [i] = ti;
			}

			isReady = true;
#else

			byte* raw;
			byte* tailor;
			uint size;
			uint idx = 0;

#if USE_MANAGED_RESOURCE
			IntPtr ptr = GetResource ("collation.core.bin");
			if (ptr == IntPtr.Zero)
				return;
			raw = (byte*) ((void*) ptr);
			ptr = GetResource ("collation.tailoring.bin");
			if (ptr == IntPtr.Zero)
				return;
			tailor = (byte*) ((void*) ptr);
#else
			int rawsize;
			int trawsize;

			lock (forLock) {
				load_collation_resource (corlibPath, CollationResourceCore, &raw, &rawsize);
				load_collation_resource (corlibPath, CollationResourceTailoring, &tailor, &trawsize);
				load_collation_resource (corlibPath, CollationResourceTailoringChars, &tailorChars, &trawsize);
			}
#endif

			if (raw == null || tailor == null)
				return;
			// check resource version
			if (raw [0] != UUtil.ResourceVersion ||
				tailor [0] != UUtil.ResourceVersion)
				return;

			idx = 1;
			size = UInt32FromBytePtr (raw, idx);
			idx += 4;
			ignorableFlags = raw + idx;
			idx += size;

			size = UInt32FromBytePtr (raw, idx);
			idx += 4;
			categories = raw + idx;
			idx += size;

			size = UInt32FromBytePtr (raw, idx);
			idx += 4;
			level1 = raw + idx;
			idx += size;

			size = UInt32FromBytePtr (raw, idx);
			idx += 4;
			level2 = raw + idx;
			idx += size;

			size = UInt32FromBytePtr (raw, idx);
			idx += 4;
			level3 = raw + idx;
			idx += size;

//			size = UInt32FromBytePtr (raw, idx);
//			idx += 4;
//			widthCompat = (ushort*) (raw + idx);
//			idx += size * 2;

			// tailoring

			idx = 1;
			uint count = UInt32FromBytePtr (tailor, idx);
			idx += 4;
			tailoringInfos = new TailoringInfo [count];
			for (int i = 0; i < count; i++) {
				int i1 = (int) UInt32FromBytePtr (tailor, idx);
				idx += 4;
				int i2 = (int) UInt32FromBytePtr (tailor, idx);
				idx += 4;
				int i3 = (int) UInt32FromBytePtr (tailor, idx);
				idx += 4;
				TailoringInfo ti = new TailoringInfo (
					i1, i2, i3, tailor [idx++] != 0);
				tailoringInfos [i] = ti;
			}
			idx += 2; // dummy
			// tailorings
			count = UInt32FromBytePtr (tailor, idx);
			idx += 4;

			tailoringArr = new char [count];
			for (int i = 0; i < count; i++, idx += 2)
				tailoringArr [i] = (char) (tailor [idx] + (tailor [idx + 1] << 8));
			isReady = true;
#endif
		}