Exemple #1
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="script">script subtag</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, Script?script, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Script     = script;
     PrivateUse = privateUseSubtags;
 }
        internal static PrivateUseSubtags Parse(LanguageTag.TokenEnumerator tokens)
        {
            var result = new PrivateUseSubtags();

            if (!tokens.TokenIs(Singleton))
            {
                throw new FormatException("unexpected subtag '" + tokens.Token + "'");
            }

            var subtags = new List <string>();

            while (tokens.NextTokenAvailable)             // get all subtags
            {
                tokens.ToNextToken();
                subtags.Add(ValidateSubtag(tokens.Token));
            }

            if (subtags.Count == 0)
            {
                throw new FormatException("private use subtags not contain elements");
            }

            result._subtags = subtags.ToArray();
            return(result);
        }
Exemple #3
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="variants">enumarate of variant subtags</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, IEnumerable <Variant> variants, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Variants   = VariantCollection.Create(Language, Script, variants);
     PrivateUse = privateUseSubtags;
 }
Exemple #4
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="region">region subtag</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, Region?region, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Region     = region;
     PrivateUse = privateUseSubtags;
 }
Exemple #5
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="extSubtags">enumarate of extensions subtags</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, IEnumerable <ExtensionSubtag> extSubtags, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Extensions = new ExtensionSubtagCollection(extSubtags);
     PrivateUse = privateUseSubtags;
 }
Exemple #6
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="script">script subtag</param>
 /// <param name="region">region subtag</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, Script?script, Region?region, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Script     = script;
     Region     = region;
     PrivateUse = privateUseSubtags;
 }
Exemple #7
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="variants">enumarate of variant subtags</param>
 /// <param name="extSubtags">enumarate of extensions subtags</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, IEnumerable <Variant> variants, IEnumerable <ExtensionSubtag> extSubtags, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Variants   = VariantCollection.Create(Language, Script, variants);
     Extensions = new ExtensionSubtagCollection(extSubtags);
     PrivateUse = privateUseSubtags;
 }
        public void Empty()
        {
            var empty = new PrivateUseSubtags();

            Assert.IsTrue(empty.IsEmpty);
            Assert.AreEqual("", empty.ToString());
            Assert.That(empty.ToArray(), Is.Empty);
        }
Exemple #9
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="script">script subtag</param>
 /// <param name="region">region subtag</param>
 /// <param name="variants">enumarate of variant subtags</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, Script?script, Region?region, IEnumerable <Variant> variants, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Script     = script;
     Region     = region;
     Variants   = VariantCollection.Create(Language, Script, variants);
     PrivateUse = privateUseSubtags;
 }
Exemple #10
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="script">script subtag</param>
 /// <param name="region">region subtag</param>
 /// <param name="extSubtags">enumarate of extensions subtags</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, Script?script, Region?region, IEnumerable <ExtensionSubtag> extSubtags, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Script     = script;
     Region     = region;
     Extensions = new ExtensionSubtagCollection(extSubtags);
     PrivateUse = privateUseSubtags;
 }
Exemple #11
0
        private void InternalParse(string text)
        {
            var gf = Grandfathered.GetPreferredValue(text);

            if (gf != null)
            {
                text = gf;
            }

            var tokens = new TokenEnumerator(text);

            if (tokens.TokenIs(PrivateUseSubtags.Singleton))
            {
                PrivateUse = PrivateUseSubtags.Parse(tokens);
                return;
            }

            Language = tokens.ParseLanguage();

            if (!tokens.CurrentTokenAvailable)
            {
                return;
            }

            Script = tokens.TryParseScript();

            if (!tokens.CurrentTokenAvailable)
            {
                return;
            }

            Region = tokens.TryParseRegion();

            if (!tokens.CurrentTokenAvailable)
            {
                return;
            }

            Variants = VariantCollection.TryParse(Language, Script, tokens);

            if (!tokens.CurrentTokenAvailable)
            {
                return;
            }

            Extensions = ExtensionSubtagCollection.TryParse(tokens);

            if (!tokens.CurrentTokenAvailable)
            {
                return;
            }

            PrivateUse = PrivateUseSubtags.Parse(tokens);
        }
        public void ParseFail(string text)
        {
            var pu1 = PrivateUseSubtags.TryParse(text);

            Assert.That(pu1.HasValue, Is.False);

            PrivateUseSubtags pu2;

            Assert.That(PrivateUseSubtags.TryParse(text, out pu2), Is.False);

            Assert.Throws <FormatException>(() => PrivateUseSubtags.Parse(text));
        }
 /// <summary>
 /// Converts the string representation of a private use subtags
 /// </summary>
 /// <returns>true if s was converted successfully; otherwise, false.</returns>
 public static bool TryParse(string text, out PrivateUseSubtags result)
 {
     try
     {
         result = Parse(text);
         return(true);
     }
     catch (FormatException)
     {
         result = new PrivateUseSubtags();
         return(false);
     }
 }
        public void TryParse(string text, string[] subtags)
        {
            var pu1 = PrivateUseSubtags.TryParse(text);

            Assert.That(pu1.Value, Is.EquivalentTo(subtags));

            PrivateUseSubtags pu2;

            Assert.That(PrivateUseSubtags.TryParse(text, out pu2), Is.True);
            Assert.That(pu2, Is.EquivalentTo(subtags));

            Assert.That(pu1, Is.EqualTo(pu2));
        }
        public void Equals()
        {
            var tag1 = new PrivateUseSubtags();
            var tag2 = (object)tag1;

            var tag3 = PrivateUseSubtags.Parse("x-aaa");
            var tag4 = (object)PrivateUseSubtags.Parse("x-aaa");

            var tag5 = PrivateUseSubtags.Parse("x-aaa-bbb");

            Assert.IsFalse(tag1.Equals(null));
            Assert.IsTrue(tag1.Equals(tag2));
            Assert.AreEqual(tag1, tag1);
            Assert.AreNotEqual(tag1, tag3);
            Assert.AreEqual(tag3, tag3);
            Assert.AreEqual(tag3, tag4);
            Assert.AreNotEqual(tag4, tag5);
        }
Exemple #16
0
 public LanguageTag(PrivateUseSubtags privateUseSubtags)
     : this()
 {
     PrivateUse = privateUseSubtags;
 }
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 public bool Equals(PrivateUseSubtags other)
 {
     return(_subtags.IsEquivalent(other._subtags));
 }
Exemple #18
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="privateUseSubtags">private use subtag</param>
 public LanguageTag(Language lang, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     PrivateUse = privateUseSubtags;
 }
        public void Contains(string subtagText, string tag, bool expected)
        {
            var pu = subtagText == null ? new PrivateUseSubtags() : PrivateUseSubtags.Parse(subtagText);

            Assert.That(pu.Contains(tag), Is.EqualTo(expected));
        }