parseDecimal static method
Strict decimal parse: throws IntegerError on overflow, unlike the wrapping operators.
Implementation
static Uint128 parseDecimal(String s) {
if (s.isEmpty || !RegExp(r'^[0-9]+$').hasMatch(s)) {
throw ArgumentException.invalidOperationArguments(
"parseDecimal",
reason: 'Invalid decimal literal.',
details: {"value": s},
);
}
var acc = Uint128.zero;
final ten = Uint128(10);
for (final rune in s.codeUnits) {
final digit = Uint128(rune - 0x30);
final scaled = acc.mulChecked(ten); // throws on overflow
final next = scaled + digit;
if (next < scaled) {
throw IntegerError.overflow;
}
acc = next;
}
return acc;
}