call method
Implementation
String call(String fmt, var args) {
String ret = '';
int offset = 0;
int argOffset = 0;
if (args is! List) {
throw new ArgumentError('Expecting list as second argument');
}
for (Match m in specifier.allMatches(fmt)) {
String? _parameter = m[1];
String? _flags = m[2];
String? _width = m[3];
String? _precision = m[4];
String? _type = m[5];
String _argStr = '';
Map _options = {
'is_upper': false,
'width': -1,
'precision': -1,
'length': -1,
'radix': 10,
'sign': '',
'specifier_type': _type,
};
_parseFlags(_flags ?? "").forEach((var K, var V) {
_options[K] = V;
});
// The argument we want to deal with
var _arg = _parameter == null ? null : args[int.parse(_parameter)];
// parse width
if (_width != null) {
_options['width'] = (_width == '*' ? args[argOffset++] : int.parse(_width));
}
// parse precision
if (_precision != null) {
_options['precision'] = (_precision == '*' ? args[argOffset++] : int.parse(_precision));
}
// grab the argument we'll be dealing with
if (_arg == null && _type != '%') {
_arg = args[argOffset++];
}
_options['is_upper'] = uppercaseRx.hasMatch(_type ?? "");
if (_type == '%') {
if ((_flags?.length ?? 0) > 0 || _width != null || _precision != null) {
throw new Exception('"%" does not take any flags');
}
_argStr = '%';
} else if (this._formatMap.containsKey(_type)) {
var formatEntry = _formatMap[_type ?? ""];
if (formatEntry != null) {
_argStr = formatEntry(_arg, _options).asString();
}
}
// Add the pre-format string to the return
ret += fmt.substring(offset, m.start);
offset = m.end;
ret += _argStr;
}
return ret += fmt.substring(offset);
}