asString method
Implementation
String asString() {
String ret = '';
if (!_hasInit) {
return ret;
}
if (_output != null) {
return _output ?? "";
}
if (options['add_space'] && options['sign'] == '' && (_arg ?? 0) >= 0) {
options['sign'] = ' ';
}
if ((_arg ?? 0).isInfinite) {
if ((_arg ?? 0).isNegative) {
options['sign'] = '-';
}
ret = 'inf';
options['padding_char'] = ' ';
}
if ((_arg ?? 0).isNaN) {
ret = 'nan';
options['padding_char'] = ' ';
}
if (options['precision'] == -1) {
options['precision'] = 6;
} else if (formatType == 'g' && options['precision'] == 0) {
options['precision'] = 1;
}
if (_arg is num) {
if (_isNegative) {
options['sign'] = '-';
}
if (formatType == 'e') {
ret = asExponential(options['precision'], removeTrailingZeros: false);
} else if (formatType == 'f') {
ret = asFixed(options['precision'], removeTrailingZeros: false);
} else {
// type == g
int _exp = _exponent;
var sigDigs = options['precision'];
if (-4 <= _exp && _exp < options['precision']) {
sigDigs -= _decimal;
num precision = max(options['precision'] - 1 - _exp, sigDigs);
ret = asFixed(precision.toNumInt,
removeTrailingZeros: !options['alternate_form']);
} else {
ret = asExponential(options['precision'] - 1,
removeTrailingZeros: !options['alternate_form']);
}
}
}
var minChars = options['width'];
num strLen = ret.length + options['sign'].length;
String padding = '';
if (minChars > strLen) {
if (options['padding_char'] == '0' && !options['left_align']) {
padding = Formatter.getPadding(minChars - strLen, '0');
} else {
padding = Formatter.getPadding(minChars - strLen, ' ');
}
}
if (options['left_align']) {
ret = "${options['sign']}$ret$padding";
} else if (options['padding_char'] == '0') {
ret = "${options['sign']}$padding$ret";
} else {
ret = "$padding${options['sign']}$ret";
}
if (options['is_upper']) {
ret = ret.toUpperCase();
}
return (_output = ret);
}