static private void VerifyParseIsSyntacticEquivalent(string simplestRule, string syntacticEquivalent)
		{
			var parser = new SimpleRulesParser();
			string expected = parser.ConvertToIcuRules(simplestRule);
			string actual = parser.ConvertToIcuRules(syntacticEquivalent);
			Assert.AreEqual(expected, actual);
		}
Exemple #2
0
        static private void VerifyParseIsSyntacticEquivalent(string simplestRule, string syntacticEquivalent)
        {
            var    parser   = new SimpleRulesParser();
            string expected = parser.ConvertToIcuRules(simplestRule);
            string actual   = parser.ConvertToIcuRules(syntacticEquivalent);

            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void ConvertToIcuRules_TwoSingleElements()
        {
            var    parser = new SimpleRulesParser();
            string result = parser.ConvertToIcuRules("a A");

            Assert.AreEqual(IcuStart + "a << A", result);
        }
		static private void VerifyExpectedIcuFromActualSimple(string icuExpected, string shoeboxActual)
		{
			var parser = new SimpleRulesParser();
			string icuRulesActual = parser.ConvertToIcuRules(shoeboxActual);
			VerifyIcuRules(icuExpected);
			Assert.AreEqual(icuExpected, icuRulesActual);
		}
Exemple #5
0
        static private void VerifyExpectedIcuFromActualSimple(string icuExpected, string shoeboxActual)
        {
            var    parser         = new SimpleRulesParser();
            string icuRulesActual = parser.ConvertToIcuRules(shoeboxActual);

            VerifyIcuRules(icuExpected);
            Assert.AreEqual(icuExpected, icuRulesActual);
        }
Exemple #6
0
        static private void VerifyParserError(string errorId, string rules, long line, long column)
        {
            try
            {
                var parser = new SimpleRulesParser();
                parser.ConvertToIcuRules(rules);
            }
            catch (ParserErrorException e)
            {
                Assert.AreEqual(errorId, e.ParserError.ErrorId);
                Assert.AreEqual(line, e.ParserError.Line);
                Assert.AreEqual(column, e.ParserError.Column);

                throw;
            }
        }
		static private void VerifyParserError(string errorId, string rules, long line, long column)
		{
			try
			{
				var parser = new SimpleRulesParser();
				parser.ConvertToIcuRules(rules);
			}
			catch (ParserErrorException e)
			{
				Assert.AreEqual(errorId, e.ParserError.ErrorId);
				Assert.AreEqual(line, e.ParserError.Line);
				Assert.AreEqual(column, e.ParserError.Column);

				throw;
			}
		}
Exemple #8
0
        private void WriteCollationRulesFromCustomSimple(XmlWriter writer, XmlReader reader, WritingSystemDefinitionV1 ws)
        {
            Debug.Assert(writer != null);
            Debug.Assert(ws != null);
            Debug.Assert(ws.SortUsing == WritingSystemDefinitionV1.SortRulesType.CustomSimple);

            var    parser = new SimpleRulesParser();
            string message;

            // avoid throwing exception, just don't save invalid data
            if (!parser.ValidateSimpleRules(ws.SortRules ?? string.Empty, out message))
            {
                return;
            }
            string icu = parser.ConvertToIcuRules(ws.SortRules ?? string.Empty);

            WriteCollationRulesFromICUString(writer, reader, icu);
        }
		public override bool Validate(out string message)
		{
			if (IsValid)
			{
				message = null;
				return true;
			}

			var parser = new SimpleRulesParser();
			if (parser.ValidateSimpleRules(SimpleRules, out message))
			{
				CollationRules = parser.ConvertToIcuRules(SimpleRules);
				IsValid = true;
				return true;
			}
			CollationRules = string.Empty;
			IsValid = false;
			return false;
		}
Exemple #10
0
        public override bool Validate(out string message)
        {
            if (IsValid)
            {
                message = null;
                return(true);
            }

            var parser = new SimpleRulesParser();

            if (parser.ValidateSimpleRules(SimpleRules, out message))
            {
                CollationRules = parser.ConvertToIcuRules(SimpleRules);
                IsValid        = true;
                return(true);
            }
            CollationRules = string.Empty;
            IsValid        = false;
            return(false);
        }
Exemple #11
0
        private static AddSortKeysToXml.SortKeyGenerator GetSortKeyGeneratorFromArgument(string s)
        {
            string icuRules = null;

            if (s.StartsWith("icu:", StringComparison.CurrentCultureIgnoreCase))
            {
                icuRules = s.Substring(4);
            }
            else if (s.StartsWith("simple:", StringComparison.CurrentCultureIgnoreCase))
            {
                var parser = new SimpleRulesParser();
                icuRules = parser.ConvertToIcuRules(s.Substring(7));
            }

            if (icuRules != null)
            {
                var collator = new IcuRulesCollator(icuRules);
                return(collator.GetSortKey);
            }
            return(CultureInfo.GetCultureInfo(s).CompareInfo.GetSortKey);
        }
		public void ConvertToIcuRules_TwoSingleElements()
		{
			var parser = new SimpleRulesParser();
			string result = parser.ConvertToIcuRules("a A");
			Assert.AreEqual(IcuStart + "a << A", result);
		}
Exemple #13
0
		private void WriteCollationRulesFromCustomSimple(XmlWriter writer, XmlReader reader, WritingSystemDefinitionV1 ws)
		{
			Debug.Assert(writer != null);
			Debug.Assert(ws != null);
			Debug.Assert(ws.SortUsing == WritingSystemDefinitionV1.SortRulesType.CustomSimple);

			var parser = new SimpleRulesParser();
			string message;
			// avoid throwing exception, just don't save invalid data
			if (!parser.ValidateSimpleRules(ws.SortRules ?? string.Empty, out message))
			{
				return;
			}
			string icu = parser.ConvertToIcuRules(ws.SortRules ?? string.Empty);
			WriteCollationRulesFromICUString(writer, reader, icu);
		}