public void ConvertToPalasoConformPrivateUseRfc5646Tag(string language, string script, string region, string variant)
        {
            string newVariant    = "";
            string newPrivateUse = "";

            _script = script;
            _region = region;

            if (!String.IsNullOrEmpty(variant))
            {
                WritingSystemDefinition.SplitVariantAndPrivateUse(variant, out newVariant, out newPrivateUse);
            }
            var privateUseSubtagsWithoutXs = StripXs(newPrivateUse);
            var languageSubtagsWithoutXs   = StripXs(language);

            newPrivateUse = String.Join("-", (languageSubtagsWithoutXs.Union(privateUseSubtagsWithoutXs)).Where(str => !String.IsNullOrEmpty(str)).ToArray());

            _variant = WritingSystemDefinition.ConcatenateVariantAndPrivateUse(newVariant, newPrivateUse);

            if (!(String.IsNullOrEmpty(script) &&
                  String.IsNullOrEmpty(region) &&
                  String.IsNullOrEmpty(newVariant))
                )
            {
                _language = "qaa";
            }
        }
Exemple #2
0
        public void ConcatenateVariantAndPrivateUse_BogusVariantBadprivateUse_HappilyGluesTheTwoTogether()
        {
            string concatenatedVariantAndPrivateUse = WritingSystemDefinition.ConcatenateVariantAndPrivateUse("bogusvariant", "etic-emic-audio");

            Assert.That(concatenatedVariantAndPrivateUse, Is.EqualTo("bogusvariant-x-etic-emic-audio"));
        }
Exemple #3
0
        public void ConcatenateVariantAndPrivateUse_VariantAndPrivateUseWithCapitalXDash_ReturnsConcatenatedVariantAndPrivateUse()
        {
            string concatenatedVariantAndPrivateUse = WritingSystemDefinition.ConcatenateVariantAndPrivateUse("1901", "X-audio");

            Assert.That(concatenatedVariantAndPrivateUse, Is.EqualTo("1901-X-audio"));
        }
Exemple #4
0
        public void ConcatenateVariantAndPrivateUse_PrivateUseWithxDashOnly_ReturnsPrivateUseWithxDash()
        {
            string concatenatedVariantAndPrivateUse = WritingSystemDefinition.ConcatenateVariantAndPrivateUse("", "x-audio");

            Assert.That(concatenatedVariantAndPrivateUse, Is.EqualTo("x-audio"));
        }
Exemple #5
0
        public void ConcatenateVariantAndPrivateUse_VariantOnly_ReturnsVariant()
        {
            string concatenatedVariantAndPrivateUse = WritingSystemDefinition.ConcatenateVariantAndPrivateUse("1901", String.Empty);

            Assert.That(concatenatedVariantAndPrivateUse, Is.EqualTo("1901"));
        }
        public void ConvertToPalasoConformPrivateUseRfc5646Tag(string flexConformPrivateUseRfc5646Tag)
        {
            string language   = String.Empty;
            string script     = String.Empty;
            string region     = String.Empty;
            string variant    = String.Empty;
            string privateUse = String.Empty;

            var tokens = flexConformPrivateUseRfc5646Tag.Split(new[] { '-' });

            for (int position = 0; position < tokens.Length; ++position)
            {
                string currentToken = tokens[position];
                if (position == 0)
                {
                    if (!currentToken.Equals("x", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new ValidationException(String.Format("The rfctag {0} does not start with 'x-' or 'X-'.",
                                                                    flexConformPrivateUseRfc5646Tag));
                    }
                    language = currentToken;
                }
                else if (position == 1 && !StandardTags.IsValidIso15924ScriptCode(currentToken))
                {
                    language = language + '-' + currentToken;
                    continue;
                }
                else if (StandardTags.IsValidIso15924ScriptCode(currentToken))
                {
                    if (!String.IsNullOrEmpty(region) || !String.IsNullOrEmpty(variant))
                    {
                        throw new ValidationException(
                                  String.Format(
                                      "The rfctag '{0}' contains a misplaced Script subtag (i.e. it was preceded by a region or variant subtag.",
                                      flexConformPrivateUseRfc5646Tag));
                    }
                    script = currentToken;
                }
                else if (StandardTags.IsValidIso3166Region(currentToken))
                {
                    if (!String.IsNullOrEmpty(variant))
                    {
                        throw new ValidationException(
                                  String.Format(
                                      "The rfctag '{0}' contains a misplaced Region subtag (i.e. it was preceded by a variant subtag.",
                                      flexConformPrivateUseRfc5646Tag));
                    }
                    region = currentToken;
                }
                else if (StandardTags.IsValidRegisteredVariant(currentToken))
                {
                    variant = variant + currentToken;
                }
                else
                {
                    privateUse = String.IsNullOrEmpty(privateUse) ? currentToken : privateUse + '-' + currentToken;
                }
            }
            variant = WritingSystemDefinition.ConcatenateVariantAndPrivateUse(variant, privateUse);
            ConvertToPalasoConformPrivateUseRfc5646Tag(language, script, region, variant);
        }