Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets an enumeration associated with the given Bidirection Class
        /// </summary>
        /// <param name="bidiClass">The Bidi Class value</param>
        /// <returns>
        /// Returns the only instance that matches the requested value.
        /// Thus two calls will get the same instance.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public static UcdProperty GetInstance(LgBidiCategory bidiClass)
        {
            InitializeHashTables();
            Dictionary <int, UcdProperty> propertyHash = s_ucdPropertyDict[UcdCategories.bidiClass];

            return(propertyHash[(int)bidiClass]);
        }
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets an enumeration associated with the given Bidirection Class
		/// </summary>
		/// <param name="bidiClass">The Bidi Class value</param>
		/// <returns>
		/// Returns the only instance that matches the requested value.
		/// Thus two calls will get the same instance.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static UcdProperty GetInstance(LgBidiCategory bidiClass)
		{
			InitializeHashTables();
			Dictionary<int, UcdProperty> propertyHash = s_ucdPropertyDict[UcdCategories.bidiClass];
			return propertyHash[(int)bidiClass];
		}
Example #3
0
		/// <summary>
		/// Checks all the values of a character in the UnicodeData.txt.
		/// Checks: fields 1-8,11-14
		/// (Skips, 9 and 10, the "Bidi Mirrored" and "Unicode Version 1"
		/// </summary>
		/// <param name="puaIndex"></param><param name="puaName"></param>
		/// <param name="puaGenCat"></param><param name="puaCombiningClass"></param>
		/// <param name="puaBidiClass"></param><param name="puaDecomposition"></param>
		/// <param name="puaNumeric"></param><param name="puaNumericValue"></param>
		/// <param name="puaComment"></param><param name="puaToUpper"></param>
		/// <param name="puaToLower"></param><param name="puaToTitle"></param>
		public static void Check_PUA(
			int puaIndex,
			string puaName,
			LgGeneralCharCategory puaGenCat,
			int puaCombiningClass,
			LgBidiCategory puaBidiClass,
			string puaDecomposition,
			bool puaNumeric,
			int puaNumericValue,
			string puaComment,
			int puaToUpper,
			int puaToLower,
			int puaToTitle
			)
		{
			string name = "";
			LgGeneralCharCategory genCategory = LgGeneralCharCategory.kccCn;
			int combiningClass = 0;
			string decomposition = "None";
			LgBidiCategory bidiCategory = LgBidiCategory.kbicL;
			string fullDecomp = "I have no clue";
			bool isNumber = false;
			int numericValue = -1;
			int upper = -1;
			int lower = -1;
			int title = -1;
			string comment = "<none>";

			//Getting the character name at the memory address specified
			ILgCharacterPropertyEngine charPropEngine = LgIcuCharPropEngineClass.Create();
			try
			{
				string icuDataDir = GetIcuDataDir();
				Icu.SetDataDirectory(icuDataDir);
				Icu.UErrorCode error;
				Icu.UCharNameChoice choice = Icu.UCharNameChoice.U_UNICODE_CHAR_NAME;
				int len = Icu.u_CharName(puaIndex, choice, out name, out error);
				genCategory = charPropEngine.get_GeneralCategory(puaIndex);
				combiningClass = charPropEngine.get_CombiningClass(puaIndex);
				bidiCategory = charPropEngine.get_BidiCategory(puaIndex);
				decomposition = charPropEngine.get_Decomposition(puaIndex);
				fullDecomp = charPropEngine.get_FullDecomp(puaIndex);
				// Note: isNumber merely checks the General category, it doesn't check to see if there is a valid numeric value.
				isNumber = charPropEngine.get_IsNumber(puaIndex);
				if(isNumber)
					numericValue = charPropEngine.get_NumericValue(puaIndex);
				comment = charPropEngine.get_Comment(puaIndex);

				upper = charPropEngine.get_ToUpperCh(puaIndex);
				lower = charPropEngine.get_ToLowerCh(puaIndex);
				title = charPropEngine.get_ToTitleCh(puaIndex);
			}
			finally
			{
				// Must release pointer to free memory-mapping before we try to restore files.
				Marshal.ReleaseComObject(charPropEngine);
				charPropEngine = null;
				Icu.Cleanup();		// clean up the ICU files / data
			}

			// StringWriter used to print hexadecimal values in the error messages.
			StringWriter stringWriter = new StringWriter(new System.Globalization.NumberFormatInfo());

			string errorMessage = "PUA Character " +
				puaIndex.ToString("x",new System.Globalization.NumberFormatInfo()) +
				" has an incorrect ";

			//Check Name [1]
			Assert.AreEqual(puaName, name, errorMessage + "name.");

			//Check general category [2]
			Assert.AreEqual(puaGenCat, genCategory, errorMessage + "general category.");

			//Check combining class [3]
			Assert.AreEqual(puaCombiningClass, combiningClass, errorMessage + "combining class.");

			//Check Bidi class [4]
			Assert.AreEqual(puaBidiClass, bidiCategory, errorMessage + "bidi class value.");

			//Check Decomposition [5]
			stringWriter.WriteLine(errorMessage + "decomposition.");
			stringWriter.WriteLine("Decomposition, {0:x}, is incorrect",(int)decomposition[0]);
			Assert.AreEqual(puaDecomposition, decomposition, stringWriter.ToString());

			//Check Numeric Value [6,7,8]
			if(puaNumeric != isNumber)
				Assert.AreEqual(puaNumeric,isNumber,errorMessage +
					"numeric type (i.e. does or doesn't have a numeric value when it should be the other).");
			if(puaNumeric)
				Assert.AreEqual(puaNumericValue, numericValue, errorMessage + "numeric value.");
			//Check ISO Comment [11]
			Assert.AreEqual(puaComment,comment, errorMessage + "ISO commment");

			//Check uppercase [12]
			stringWriter.Flush();
			stringWriter.WriteLine(errorMessage + "upper case.");
			stringWriter.WriteLine("Found uppercase value: {0:x}",upper);
			Assert.AreEqual(puaToUpper,upper, stringWriter.ToString());
			//Check lowercase [13]
			Assert.AreEqual(puaToLower,lower, errorMessage + "lower case.");
			//Check titlecase [14]
			Assert.AreEqual(puaToTitle,title, errorMessage + "title case.");
		}
Example #4
0
        /// <summary>
        /// Checks all the values of a character in the UnicodeData.txt.
        /// Checks: fields 1-8,11-14
        /// (Skips, 9 and 10, the "Bidi Mirrored" and "Unicode Version 1"
        /// </summary>
        /// <param name="puaIndex"></param><param name="puaName"></param>
        /// <param name="puaGenCat"></param><param name="puaCombiningClass"></param>
        /// <param name="puaBidiClass"></param><param name="puaDecomposition"></param>
        /// <param name="puaNumeric"></param><param name="puaNumericValue"></param>
        /// <param name="puaComment"></param><param name="puaToUpper"></param>
        /// <param name="puaToLower"></param><param name="puaToTitle"></param>
        public static void Check_PUA(
            int puaIndex,
            string puaName,
            LgGeneralCharCategory puaGenCat,
            int puaCombiningClass,
            LgBidiCategory puaBidiClass,
            string puaDecomposition,
            bool puaNumeric,
            int puaNumericValue,
            string puaComment,
            int puaToUpper,
            int puaToLower,
            int puaToTitle
            )
        {
            string name = "";
            LgGeneralCharCategory genCategory = LgGeneralCharCategory.kccCn;
            int            combiningClass     = 0;
            string         decomposition      = "None";
            LgBidiCategory bidiCategory       = LgBidiCategory.kbicL;
            string         fullDecomp         = "I have no clue";
            bool           isNumber           = false;
            int            numericValue       = -1;
            int            upper   = -1;
            int            lower   = -1;
            int            title   = -1;
            string         comment = "<none>";

            //Getting the character name at the memory address specified
            ILgCharacterPropertyEngine charPropEngine = LgIcuCharPropEngineClass.Create();

            try
            {
                string icuDataDir = GetIcuDataDir();
                Icu.SetDataDirectory(icuDataDir);
                Icu.UErrorCode      error;
                Icu.UCharNameChoice choice = Icu.UCharNameChoice.U_UNICODE_CHAR_NAME;
                int len = Icu.u_CharName(puaIndex, choice, out name, out error);
                genCategory    = charPropEngine.get_GeneralCategory(puaIndex);
                combiningClass = charPropEngine.get_CombiningClass(puaIndex);
                bidiCategory   = charPropEngine.get_BidiCategory(puaIndex);
                decomposition  = charPropEngine.get_Decomposition(puaIndex);
                fullDecomp     = charPropEngine.get_FullDecomp(puaIndex);
                // Note: isNumber merely checks the General category, it doesn't check to see if there is a valid numeric value.
                isNumber = charPropEngine.get_IsNumber(puaIndex);
                if (isNumber)
                {
                    numericValue = charPropEngine.get_NumericValue(puaIndex);
                }
                comment = charPropEngine.get_Comment(puaIndex);

                upper = charPropEngine.get_ToUpperCh(puaIndex);
                lower = charPropEngine.get_ToLowerCh(puaIndex);
                title = charPropEngine.get_ToTitleCh(puaIndex);
            }
            finally
            {
                // Must release pointer to free memory-mapping before we try to restore files.
                Marshal.ReleaseComObject(charPropEngine);
                charPropEngine = null;
                Icu.Cleanup();                          // clean up the ICU files / data
            }

            // StringWriter used to print hexadecimal values in the error messages.
            StringWriter stringWriter = new StringWriter(new System.Globalization.NumberFormatInfo());

            string errorMessage = "PUA Character " +
                                  puaIndex.ToString("x", new System.Globalization.NumberFormatInfo()) +
                                  " has an incorrect ";

            //Check Name [1]
            Assert.AreEqual(puaName, name, errorMessage + "name.");

            //Check general category [2]
            Assert.AreEqual(puaGenCat, genCategory, errorMessage + "general category.");

            //Check combining class [3]
            Assert.AreEqual(puaCombiningClass, combiningClass, errorMessage + "combining class.");

            //Check Bidi class [4]
            Assert.AreEqual(puaBidiClass, bidiCategory, errorMessage + "bidi class value.");

            //Check Decomposition [5]
            stringWriter.WriteLine(errorMessage + "decomposition.");
            stringWriter.WriteLine("Decomposition, {0:x}, is incorrect", (int)decomposition[0]);
            Assert.AreEqual(puaDecomposition, decomposition, stringWriter.ToString());

            //Check Numeric Value [6,7,8]
            if (puaNumeric != isNumber)
            {
                Assert.AreEqual(puaNumeric, isNumber, errorMessage +
                                "numeric type (i.e. does or doesn't have a numeric value when it should be the other).");
            }
            if (puaNumeric)
            {
                Assert.AreEqual(puaNumericValue, numericValue, errorMessage + "numeric value.");
            }
            //Check ISO Comment [11]
            Assert.AreEqual(puaComment, comment, errorMessage + "ISO commment");

            //Check uppercase [12]
            stringWriter.Flush();
            stringWriter.WriteLine(errorMessage + "upper case.");
            stringWriter.WriteLine("Found uppercase value: {0:x}", upper);
            Assert.AreEqual(puaToUpper, upper, stringWriter.ToString());
            //Check lowercase [13]
            Assert.AreEqual(puaToLower, lower, errorMessage + "lower case.");
            //Check titlecase [14]
            Assert.AreEqual(puaToTitle, title, errorMessage + "title case.");
        }