LocaleParser constructor

LocaleParser(
  1. String localeId
)

Parses Unicode CLDR Locale Identifiers.

This method does not parse all BCP 47 tags. See BCP 47 Conformance for details.

localeId may not be null.

Parsing failed if there are any entries in problems.

Implementation

LocaleParser(String localeId) {
  ArgumentError.notNull(localeId);

  // Calling toLowerCase unconditionally should be efficient if
  // string_patch.dart is in use:
  // https://github.com/dart-lang/sdk/blob/cabaa78cc57d08bcfcd75bfe99a42c19ed497d26/runtime/lib/string_patch.dart#L1178
  localeId = localeId.toLowerCase();
  if (localeId == 'root') {
    return;
  }

  _subtags = localeId.split(separators);
  _current = _subtags[0];

  var scriptFound = false;
  if (acceptLanguage()) {
    _languageCode = replaceDeprecatedLanguageSubtag(_accepted);
    scriptFound = acceptScript();
  } else {
    scriptFound = acceptScript();
    if (!scriptFound) {
      problems.add('bad language/script');
    }
  }
  if (scriptFound) {
    _scriptCode = toCapCase(_accepted);
  }
  if (acceptRegion()) {
    _countryCode = replaceDeprecatedRegionSubtag(_accepted.toUpperCase());
  }
  acceptVariants();
  _variants = _acceptedList;

  processExtensions();

  if (!atEnd()) {
    problems.add('bad subtag "$_current"');
  }
}