operator [] method
Retrieves a single fully sanitized value for the key.
Values are always processed according to the ParamsMode.standard mode. That is, all whitespaces (including line terminators) are converted into spaces (U+0020); multiple spaces are collapsed into a single space; and spaces at either ends are trimmed. To use other modes, use the values method.
The empty string will be returned if:
- there is no value matching the
key
; - there is a value but it only contains whitespace; or
- there is a value that contains zero characters.
If there is a need to distinguish between these different values, use the values method instead.
This operator must only be used for parameters which are single valued. If the key matches multiple values: in production mode, the empty string is returned; in checked mode, an assertion error is raised. Use the values method for keys with multiple values.
Implementation
String operator [](String key) {
final values = _data[key];
if (values == null) {
return ''; // no value for key
} else if (values.length == 1) {
// Single value
return _sanitize(values[0], ParamsMode.standard);
} else {
assert(values.length == 1, 'multi-valued: do not use [] with "$key"');
return ''; // error value
}
}