コード例 #1
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        public bool Equals(VariantCollection other)
        {
            if (_variants == null)
            {
                return(other._variants == null);
            }

            if (other._variants == null)
            {
                return(false);
            }

            if (_variants.Length != other._variants.Length)
            {
                return(false);
            }

            for (int i = 0; i < _variants.Length; i++)
            {
                if (_variants[i] != other._variants[i])
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public void Equals()
        {
            var vc1 = new VariantCollection();
            var vc2 = new VariantCollection();

            var vc3 = new VariantCollection(Variant.Alalc97, Variant.Aluku);
            var vc4 = new VariantCollection(Variant.Alalc97, Variant.Aluku);

            var vc5 = new VariantCollection(Variant.Alalc97);

            Assert.IsFalse(vc1.Equals(null));
            Assert.IsTrue(vc1.Equals((object)vc2));
            Assert.AreEqual(vc1, vc1);
            Assert.AreEqual(vc1, vc2);
            Assert.AreNotEqual(vc1, vc3);
            Assert.AreEqual(vc3, vc3);
            Assert.AreEqual(vc3, vc4);
            Assert.AreNotEqual(vc4, vc5);

            Assert.IsTrue(vc1 == vc2);
            Assert.IsFalse(vc1 != vc2);

            Assert.IsTrue(vc3 != vc5);
            Assert.IsFalse(vc3 == vc5);
        }
コード例 #3
0
        public void VariantCollectionCreate(string tagText)
        {
            var tag      = new LanguageTag(tagText);
            var variants = VariantCollection.Create(tag.Language, tag.Script, tag.Variants);

            Assert.That(variants, Is.EqualTo(tag.Variants));
        }
コード例 #4
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;
 }
コード例 #5
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);
 }
コード例 #6
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>
 public LanguageTag(Language lang, Script?script, IEnumerable <Variant> variants)
     : this()
 {
     Language = lang;
     Script   = script;
     Variants = VariantCollection.Create(Language, Script, variants);
 }
コード例 #7
0
 /// <summary>
 /// Create the LanguageTag instance
 /// </summary>
 /// <param name="lang">primary language</param>
 /// <param name="region">region subtag</param>
 /// <param name="variants">enumarate of variant subtags</param>
 public LanguageTag(Language lang, Region?region, IEnumerable <Variant> variants)
     : this()
 {
     Language = lang;
     Region   = region;
     Variants = VariantCollection.Create(Language, Script, variants);
 }
コード例 #8
0
 public void VariantCollectionCreate(string tagText, Variant appendVariant)
 {
     Assert.Throws <FormatException>(() =>
     {
         var tag = new LanguageTag(tagText);
         VariantCollection.Create(tag.Language, tag.Script, tag.Variants.Union(new Variant[] { appendVariant }));
     });
 }
コード例 #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;
 }
コード例 #10
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;
 }
コード例 #11
0
ファイル: LanguageTag.cs プロジェクト: lexarchik/LanguageTag
        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);
        }