Ejemplo n.º 1
0
        public void Equals()
        {
            var ext1 = new ExtensionSubtagCollection();
            var ext2 = new ExtensionSubtagCollection();

            var ext3 = new ExtensionSubtagCollection(new ExtensionSubtag('a', "aaa"));
            var ext4 = new ExtensionSubtagCollection(new ExtensionSubtag('a', "aaa"));

            var ext5 = new ExtensionSubtagCollection(new ExtensionSubtag('a', "aaa"), new ExtensionSubtag('b', "aaa"));

            Assert.IsFalse(ext1.Equals(null));
            Assert.IsTrue(ext1.Equals((object)ext2));
            Assert.AreEqual(ext1, ext1);
            Assert.AreEqual(ext1, ext2);
            Assert.AreNotEqual(ext1, ext3);
            Assert.AreEqual(ext3, ext3);
            Assert.AreEqual(ext3, ext4);
            Assert.AreNotEqual(ext4, ext5);

            Assert.IsTrue(ext1 == ext2);
            Assert.IsFalse(ext1 != ext2);

            Assert.IsTrue(ext3 != ext5);
            Assert.IsFalse(ext3 == ext5);
        }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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>
 public LanguageTag(Language lang, IEnumerable <Variant> variants, IEnumerable <ExtensionSubtag> extSubtags)
     : this()
 {
     Language   = lang;
     Variants   = VariantCollection.Create(Language, Script, variants);
     Extensions = new ExtensionSubtagCollection(extSubtags);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="script">script subtag</param>
 /// <param name="extSubtags">enumarate of extensions subtags</param>
 public LanguageTag(Language lang, Script?script, IEnumerable <ExtensionSubtag> extSubtags)
     : this()
 {
     Language   = lang;
     Script     = script;
     Extensions = new ExtensionSubtagCollection(extSubtags);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="region">region subtag</param>
 /// <param name="extSubtags">enumarate of extensions subtags</param>
 public LanguageTag(Language lang, Region?region, IEnumerable <ExtensionSubtag> extSubtags)
     : this()
 {
     Language   = lang;
     Region     = region;
     Extensions = new ExtensionSubtagCollection(extSubtags);
 }
Ejemplo n.º 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="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;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="script">script subtag</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, Script?script, IEnumerable <Variant> variants, IEnumerable <ExtensionSubtag> extSubtags, PrivateUseSubtags privateUseSubtags)
     : this()
 {
     Language   = lang;
     Script     = script;
     Variants   = VariantCollection.Create(Language, Script, variants);
     Extensions = new ExtensionSubtagCollection(extSubtags);
     PrivateUse = privateUseSubtags;
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        internal static ExtensionSubtagCollection TryParse(LanguageTag.TokenEnumerator tokens)
        {
            var result = new ExtensionSubtagCollection();
            var subtag = ExtensionSubtag.TryParse(tokens);

            if (subtag.HasValue)
            {
                result._sortedList = new List <ExtensionSubtag>();
                do
                {
                    result.Append(subtag.Value);
                    subtag = ExtensionSubtag.TryParse(tokens);
                }while (subtag.HasValue);
            }

            return(result);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 public bool Equals(ExtensionSubtagCollection other)
 {
     return(_sortedList.IsEquivalent(other._sortedList));
 }