Exemplo n.º 1
0
        private void ReadIdentityElement(XmlReader reader, WritingSystemDefinitionV1 ws)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.Name == "identity");
            using (XmlReader identityReader = reader.ReadSubtree())
            {
                identityReader.MoveToContent();
                identityReader.ReadStartElement("identity");
                if (FindElement(identityReader, "version"))
                {
                    ws.VersionNumber = identityReader.GetAttribute("number") ?? string.Empty;
                    if (!identityReader.IsEmptyElement)
                    {
                        ws.VersionDescription = identityReader.ReadString();
                        identityReader.ReadEndElement();
                    }
                }
                string   dateTime = GetSubNodeAttributeValue(identityReader, "generation", "date");
                DateTime modified = DateTime.UtcNow;
                if (!string.IsNullOrEmpty(dateTime.Trim()) && !DateTime.TryParse(dateTime, out modified))
                {
                    //CVS format:    "$Date: 2008/06/18 22:52:35 $"
                    modified = DateTime.ParseExact(dateTime, "'$Date: 'yyyy/MM/dd HH:mm:ss $", null,
                                                   DateTimeStyles.AssumeUniversal);
                }

                ws.DateModified = modified;

                string language = GetSubNodeAttributeValue(identityReader, "language", "type");
                string script   = GetSubNodeAttributeValue(identityReader, "script", "type");
                string region   = GetSubNodeAttributeValue(identityReader, "territory", "type");
                string variant  = GetSubNodeAttributeValue(identityReader, "variant", "type");

                if ((language.StartsWith("x-", StringComparison.OrdinalIgnoreCase) || language.Equals("x", StringComparison.OrdinalIgnoreCase)))
                {
                    var flexRfcTagInterpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
                    flexRfcTagInterpreter.ConvertToPalasoConformPrivateUseRfc5646Tag(language, script, region, variant);
                    ws.SetAllComponents(flexRfcTagInterpreter.Language, flexRfcTagInterpreter.Script, flexRfcTagInterpreter.Region, flexRfcTagInterpreter.Variant);

                    _wsIsFlexPrivateUse = true;
                }
                else
                {
                    ws.SetAllComponents(language, script, region, variant);

                    _wsIsFlexPrivateUse = false;
                }
                //Set the id simply as the concatenation of whatever was in the ldml file.
                ws.Id = String.Join("-", new[] { language, script, region, variant }.Where(subtag => !String.IsNullOrEmpty(subtag)).ToArray());
                // move to end of identity node
                while (identityReader.Read())
                {
                    ;
                }
            }
            if (!reader.IsEmptyElement)
            {
                reader.ReadEndElement();
            }
        }
		public void ConvertToPalasoConformPrivateUseRfc5646Tag_LanguageSubtagTogetherWithPrivateUseContainsDuplicates_IsConvertedCorrectly()
		{
			var interpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
			interpreter.ConvertToPalasoConformPrivateUseRfc5646Tag("x-en-x-en");
			AssertThatPropertiesAreSet("", "", "", "x-en", interpreter);
		}
		public void ConvertToPalasoConformPrivateUseRfc5646Tag_xDashXDashZxxxDashAudio_IsConvertedCorrectly()
		{
			var interpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
			interpreter.ConvertToPalasoConformPrivateUseRfc5646Tag("x-x-Zxxx-AUDIO");
			AssertThatPropertiesAreSet("qaa", "Zxxx", "", "x-AUDIO", interpreter);
		}
		public void ConvertToPalasoConformPrivateUseRfc5646Tag_NoLanguageScriptPrivateUse_IsConvertedCorrectly()
		{
			var interpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
			interpreter.ConvertToPalasoConformPrivateUseRfc5646Tag("x-Zxxx-x-audio");
			AssertThatPropertiesAreSet("qaa", "Zxxx", "", "x-audio", interpreter);
		}
		public void ConvertToPalasoConformPrivateUseRfc5646Tag_PrivateUseContainsDuplicates_IsConvertedCorrectly()
		{
			var interpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
			interpreter.ConvertToPalasoConformPrivateUseRfc5646Tag("x-en-x-private-private");
			AssertThatPropertiesAreSet("", "", "", "x-en-private", interpreter);
		}
		public void ConvertToPalasoConformPrivateUseRfc5646Tag_LanguageVariant_IsConvertedCorrectly()
		{
			var interpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
			interpreter.ConvertToPalasoConformPrivateUseRfc5646Tag("x-en-fonipa");
			AssertThatPropertiesAreSet("qaa", "", "", "fonipa-x-en", interpreter);
		}
		public void ConvertToPalasoConformPrivateUseRfc5646Tag_PrivateUseContainsMultipleXs_RemovesExtraXs()
		{
			var interpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
			interpreter.ConvertToPalasoConformPrivateUseRfc5646Tag("","","","x-x-x-audio");
			AssertThatPropertiesAreSet("", "", "", "x-audio", interpreter);
		}
		public void ConvertToPalasoConformPrivateUseRfc5646Tag_LanguageIsValidRfc5646TagStartingWithX_Throws()
		{
			var interpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
			Assert.That(()=>interpreter.ConvertToPalasoConformPrivateUseRfc5646Tag("xh"), Throws.Exception.TypeOf<ValidationException>());
		}
		private void AssertThatPropertiesAreSet(string language, string script, string region, string variant, FlexConformPrivateUseRfc5646TagInterpreter interpreter)
		{
			Assert.That(interpreter.Language, Is.EqualTo(language));
			Assert.That(interpreter.Script, Is.EqualTo(script));
			Assert.That(interpreter.Region, Is.EqualTo(region));
			Assert.That(interpreter.Variant, Is.EqualTo(variant));
		}
Exemplo n.º 10
0
		private void ReadIdentityElement(XmlReader reader, WritingSystemDefinitionV1 ws)
		{
			Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.Name == "identity");
			using (XmlReader identityReader = reader.ReadSubtree())
			{
				identityReader.MoveToContent();
				identityReader.ReadStartElement("identity");
				if (FindElement(identityReader, "version"))
				{
					ws.VersionNumber = identityReader.GetAttribute("number") ?? string.Empty;
					if (!identityReader.IsEmptyElement)
					{
						ws.VersionDescription = identityReader.ReadString();
						identityReader.ReadEndElement();
					}
				}
				string dateTime = GetSubNodeAttributeValue(identityReader, "generation", "date");
				DateTime modified = DateTime.UtcNow;
				if (!string.IsNullOrEmpty(dateTime.Trim()) && !DateTime.TryParse(dateTime, out modified))
				{
					//CVS format:    "$Date: 2008/06/18 22:52:35 $"
					modified = DateTime.ParseExact(dateTime, "'$Date: 'yyyy/MM/dd HH:mm:ss $", null,
												   DateTimeStyles.AssumeUniversal);
				}

				ws.DateModified = modified;

				string language = GetSubNodeAttributeValue(identityReader, "language", "type");
				string script = GetSubNodeAttributeValue(identityReader, "script", "type");
				string region = GetSubNodeAttributeValue(identityReader, "territory", "type");
				string variant = GetSubNodeAttributeValue(identityReader, "variant", "type");

				if ((language.StartsWith("x-", StringComparison.OrdinalIgnoreCase) || language.Equals("x", StringComparison.OrdinalIgnoreCase)))
				{
					var flexRfcTagInterpreter = new FlexConformPrivateUseRfc5646TagInterpreter();
					flexRfcTagInterpreter.ConvertToPalasoConformPrivateUseRfc5646Tag(language, script, region, variant);
					ws.SetAllComponents(flexRfcTagInterpreter.Language, flexRfcTagInterpreter.Script, flexRfcTagInterpreter.Region, flexRfcTagInterpreter.Variant);

					_wsIsFlexPrivateUse = true;
				}
				else
				{
					ws.SetAllComponents(language, script, region, variant);

					_wsIsFlexPrivateUse = false;
				}
				//Set the id simply as the concatenation of whatever was in the ldml file.
				ws.Id = String.Join("-", new[] { language, script, region, variant }.Where(subtag => !String.IsNullOrEmpty(subtag)).ToArray());
				// move to end of identity node
				while (identityReader.Read()) ;
			}
			if (!reader.IsEmptyElement)
			{
				reader.ReadEndElement();
			}
		}