Exemplo n.º 1
0
        /// <summary>
        /// Remove special private use subtag sequence identified by "lvariant"
        /// and return the rest. Only used by LocaleExtensions.
        /// </summary>
        internal static string RemovePrivateuseVariant(string privuseVal)
        {
            StringTokenEnumerator itr = new StringTokenEnumerator(privuseVal, LanguageTag.Separator);

            // Note: privateuse value "abc-lvariant" is unchanged
            // because no subtags after "lvariant".

            int  prefixStart   = -1;
            bool sawPrivuseVar = false;

            while (itr.MoveNext())
            {
                if (prefixStart != -1)
                {
                    // Note: privateuse value "abc-lvariant" is unchanged
                    // because no subtags after "lvariant".
                    sawPrivuseVar = true;
                    break;
                }
                if (AsciiUtil.CaseIgnoreMatch(itr.Current, LanguageTag.PrivateUse_Variant_Prefix))
                {
                    prefixStart = itr.CurrentStart;
                }
            }
            if (!sawPrivuseVar)
            {
                return(privuseVal);
            }

            Debug.Assert(prefixStart == 0 || prefixStart > 1);
            return((prefixStart == 0) ? null : privuseVal.Substring(0, prefixStart - 1)); // ICU4N: Checked 2nd parameter
        }
Exemplo n.º 2
0
 public override bool Equals(object obj)
 {
     if (this == obj)
     {
         return(true);
     }
     if (!(obj is CaseInsensitiveString))
     {
         return(false);
     }
     return(AsciiUtil.CaseIgnoreMatch(_s, ((CaseInsensitiveString)obj).Value));
 }
Exemplo n.º 3
0
        public static bool IsExtensionSingleton(string s)
        {
            // singleton     = DIGIT               ; 0 - 9
            //               / %x41-57             ; A - W
            //               / %x59-5A             ; Y - Z
            //               / %x61-77             ; a - w
            //               / %x79-7A             ; y - z

            return((s.Length == 1) &&
                   AsciiUtil.IsAlphaString(s) &&
                   !AsciiUtil.CaseIgnoreMatch(PRIVATEUSE, s));
        }
Exemplo n.º 4
0
 public override bool Equals(Object o)
 {
     if (this == o)
     {
         return(true);
     }
     if (o is CaseInsensitiveKey)
     {
         return(AsciiUtil.CaseIgnoreMatch(_key, ((CaseInsensitiveKey)o)._key));
     }
     return(false);
 }
Exemplo n.º 5
0
        public override bool Equals(object o)
        {
            if (ReferenceEquals(this, o))
            {
                return(true);
            }

            if (o is AsciiCaseInsensitiveKey other)
            {
                return(AsciiUtil.CaseIgnoreMatch(_key, other._key));
            }

            return(false);
        }
Exemplo n.º 6
0
            public override bool Equals(object obj)
            {
                if (ReferenceEquals(this, obj))
                {
                    return(true);
                }

                if (obj is CaseInsensitiveString other)
                {
                    return(AsciiUtil.CaseIgnoreMatch(_s, other.Value));
                }

                return(false);
            }
Exemplo n.º 7
0
 public override bool Equals(object obj)
 {
     if (JDKIMPL)
     {
         return((this == obj) ||
                (obj is Key) &&
                AsciiUtil.CaseIgnoreMatch(((Key)obj)._lang, this._lang) &&
                AsciiUtil.CaseIgnoreMatch(((Key)obj)._scrt, this._scrt) &&
                AsciiUtil.CaseIgnoreMatch(((Key)obj)._regn, this._regn) &&
                ((Key)obj)._vart.Equals(_vart));    // variant is case sensitive in JDK!
     }
     return((this == obj) ||
            (obj is Key) &&
            AsciiUtil.CaseIgnoreMatch(((Key)obj)._lang, this._lang) &&
            AsciiUtil.CaseIgnoreMatch(((Key)obj)._scrt, this._scrt) &&
            AsciiUtil.CaseIgnoreMatch(((Key)obj)._regn, this._regn) &&
            AsciiUtil.CaseIgnoreMatch(((Key)obj)._vart, this._vart));
 }
Exemplo n.º 8
0
        public BaseLocale GetBaseLocale()
        {
            string language = _language;
            string script   = _script;
            string region   = _region;
            string variant  = _variant;

            // Special private use subtag sequence identified by "lvariant" will be
            // interpreted as Java variant.
            if (_extensions != null)
            {
                string privuse;
                if (_extensions.TryGetValue(PRIVUSE_KEY, out privuse) && privuse != null)
                {
                    StringTokenEnumerator itr = new StringTokenEnumerator(privuse, LanguageTag.Separator);
                    bool sawPrefix            = false;
                    int  privVarStart         = -1;
                    while (itr.MoveNext())
                    {
                        if (sawPrefix)
                        {
                            privVarStart = itr.CurrentStart;
                            break;
                        }
                        if (AsciiUtil.CaseIgnoreMatch(itr.Current, LanguageTag.PrivateUse_Variant_Prefix))
                        {
                            sawPrefix = true;
                        }
                    }
                    if (privVarStart != -1)
                    {
                        StringBuilder sb = new StringBuilder(variant);
                        if (sb.Length != 0)
                        {
                            sb.Append(BaseLocale.Separator);
                        }
                        sb.Append(privuse.Substring(privVarStart).Replace(LanguageTag.Separator, BaseLocale.Separator));
                        variant = sb.ToString();
                    }
                }
            }

            return(BaseLocale.GetInstance(language, script, region, variant));
        }
Exemplo n.º 9
0
        public static BaseLocale GetInstance(string language, string script, string region, string variant)
        {
            if (JDKIMPL)
            {
                // JDK uses deprecated ISO639.1 language codes for he, yi and id
                if (AsciiUtil.CaseIgnoreMatch(language, "he"))
                {
                    language = "iw";
                }
                else if (AsciiUtil.CaseIgnoreMatch(language, "yi"))
                {
                    language = "ji";
                }
                else if (AsciiUtil.CaseIgnoreMatch(language, "id"))
                {
                    language = "in";
                }
            }
            Key        key        = new Key(language, script, region, variant);
            BaseLocale baseLocale = CACHE.Get(key);

            return(baseLocale);
        }
Exemplo n.º 10
0
 public static bool IsPrivateusePrefixChar(char c)
 {
     return(AsciiUtil.CaseIgnoreMatch(PRIVATEUSE, new string(new char[] { c })));
 }
Exemplo n.º 11
0
 public static bool IsPrivateusePrefix(string s)
 {
     // privateuse    = "x" 1*("-" (1*8alphanum))
     return((s.Length == 1) &&
            AsciiUtil.CaseIgnoreMatch(PRIVATEUSE, s));
 }