LocaleExtensions constructor
LocaleExtensions()
Constructor.
Keys in each of the maps passed to this contructor must be syntactically valid extension keys, and must already be normalized (correct case).
Implementation
LocaleExtensions(
Map<String, String>? uExtensions,
Map<String, String>? tExtensions,
Map<String, String>? otherExtensions,
this._xExtensions)
: _uExtensions = _sortedUnmodifiable(uExtensions),
_tExtensions = _sortedUnmodifiable(tExtensions),
_otherExtensions = _sortedUnmodifiable(otherExtensions) {
// Debug-mode asserts to ensure all parameters are normalized and UTS #35
// compliant.
assert(
uExtensions == null ||
uExtensions.entries.every((e) {
if (!_uExtensionsValidKeysRE.hasMatch(e.key)) return false;
// TODO(hugovdm) reconsider this representation: "true" values are
// suppressed in canonical Unicode BCP47 Locale Identifiers, but
// we may choose to represent them as "true" in memory.
if (e.value == '' && e.key != '') return true;
if (!_uExtensionsValidValuesRE.hasMatch(e.value)) return false;
return true;
}),
'uExtensions keys must match '
'RegExp/${_uExtensionsValidKeysRE.pattern}/. '
'uExtensions values must match '
'RegExp/${_uExtensionsValidValuesRE.pattern}/. '
'uExtensions.entries: ${uExtensions.entries}.');
assert(
tExtensions == null ||
tExtensions.entries.every((e) {
if (!_tExtensionsValidKeysRE.hasMatch(e.key)) return false;
if (e.key == '') {
if (!_validTlangRE.hasMatch(e.value)) return false;
} else {
if (!_tExtensionsValidValuesRE.hasMatch(e.value)) return false;
}
return true;
}),
'tExtensions keys must match '
'RegExp/${_tExtensionsValidKeysRE.pattern}/. '
'tExtensions values other than tlang must match '
'RegExp/${_tExtensionsValidValuesRE.pattern}/. '
'Entries: ${tExtensions.entries}.');
assert(
otherExtensions == null ||
otherExtensions.entries.every((e) {
if (!_otherExtensionsValidKeysRE.hasMatch(e.key)) return false;
if (!_otherExtensionsValidValuesRE.hasMatch(e.value)) {
return false;
}
return true;
}),
'otherExtensions keys must match '
'RegExp/${_otherExtensionsValidKeysRE.pattern}. '
'otherExtensions values must match '
'RegExp/${_otherExtensionsValidValuesRE.pattern}. '
'Entries: ${otherExtensions.entries}.');
assert(
_xExtensions == null || _validXExtensionsRE.hasMatch(_xExtensions!),
'_xExtensions must match RegExp/${_validXExtensionsRE.pattern}/ '
'but is "$_xExtensions".');
}