コード例 #1
0
            protected override bool Validate(string key, string value)
            {
                Guard.ArgumentNotNull(key, "key");
                Guard.ArgumentNotNull(value, "value");
                if (key.Length != 1 && !Char.IsLetterOrDigit(key[0]))
                {
                    throw new FormatException("Singleton must be a single letter or digit");
                }
                if (!String.IsNullOrEmpty(value))
                {
                    bool result;
                    switch (key[0])
                    {
                    case 'u':
                    case 'U':
                        result = BcpLanguageTag.IsValid("root-u-" + value);
                        break;

                    case 't':
                    case 'T':
                        result = BcpLanguageTag.IsValid("root-t-" + value);
                        break;

                    case 'x':
                    case 'X':
                        result = Regex.IsMatch(value, reXValue, RegexOptions.IgnoreCase);
                        break;

                    default:
                        result = Regex.IsMatch(value, reSValue, RegexOptions.IgnoreCase);
                        break;
                    }
                    if (!result)
                    {
                        throw new FormatException(String.Format("'{0}' is not a valid sequence for {1} singleton", value, key));
                    }
                }
                return(true);
            }
コード例 #2
0
 public static bool IsStructurallyValidLanguageTag(string locale)
 {
     return(BcpLanguageTag.IsValid(locale));
 }