public InternalLocaleBuilder RemoveUnicodeLocaleAttribute(string attribute) { if (attribute == null || !UnicodeLocaleExtension.IsAttribute(attribute)) { throw new FormatException("Ill-formed Unicode locale attribute: " + attribute); } if (_uattributes != null) { _uattributes.Remove(new CaseInsensitiveString(attribute)); } return(this); }
public InternalLocaleBuilder AddUnicodeLocaleAttribute(string attribute) { if (attribute == null || !UnicodeLocaleExtension.IsAttribute(attribute)) { throw new FormatException("Ill-formed Unicode locale attribute: " + attribute); } // Use case insensitive string to prevent duplication if (_uattributes == null) { _uattributes = new HashSet <CaseInsensitiveString>(/*4*/); } _uattributes.Add(new CaseInsensitiveString(attribute)); return(this); }
/// <summary> /// Private methods parsing Unicode Locale Extension subtags. /// Duplicated attributes/keywords will be ignored. /// The input must be a valid extension subtags (excluding singleton). /// </summary> private void SetUnicodeLocaleExtension(string subtags) { // wipe out existing attributes/keywords if (_uattributes != null) { _uattributes.Clear(); } if (_ukeywords != null) { _ukeywords.Clear(); } StringTokenEnumerator itr = new StringTokenEnumerator(subtags, LanguageTag.Separator); // parse attributes while (itr.MoveNext()) { if (!UnicodeLocaleExtension.IsAttribute(itr.Current)) { break; } if (_uattributes == null) { _uattributes = new HashSet <CaseInsensitiveString>(/*4*/); } _uattributes.Add(new CaseInsensitiveString(itr.Current)); } // parse keywords CaseInsensitiveString key = null; string type; int typeStart = -1; int typeEnd = -1; while (!itr.IsDone) { if (key != null) { if (UnicodeLocaleExtension.IsKey(itr.Current)) { // next keyword - emit previous one Debug.Assert(typeStart == -1 || typeEnd != -1); type = (typeStart == -1) ? "" : subtags.Substring(typeStart, typeEnd - typeStart); // ICU4N: Corrected 2nd parameter if (_ukeywords == null) { _ukeywords = new Dictionary <CaseInsensitiveString, string>(4); } _ukeywords[key] = type; // reset keyword info CaseInsensitiveString tmpKey = new CaseInsensitiveString(itr.Current); key = _ukeywords.ContainsKey(tmpKey) ? null : tmpKey; typeStart = typeEnd = -1; } else { if (typeStart == -1) { typeStart = itr.CurrentStart; } typeEnd = itr.CurrentEnd; } } else if (UnicodeLocaleExtension.IsKey(itr.Current)) { // 1. first keyword or // 2. next keyword, but previous one was duplicate key = new CaseInsensitiveString(itr.Current); if (_ukeywords != null && _ukeywords.ContainsKey(key)) { // duplicate key = null; } } if (!itr.HasNext) { if (key != null) { // last keyword Debug.Assert(typeStart == -1 || typeEnd != -1); type = (typeStart == -1) ? "" : subtags.Substring(typeStart, typeEnd - typeStart); // ICU4N: Corrected 2nd parameter if (_ukeywords == null) { _ukeywords = new Dictionary <CaseInsensitiveString, string>(4); } _ukeywords[key] = type; } break; } itr.MoveNext(); } }