ValidatedQuantity.fromString constructor
ValidatedQuantity.fromString(
- String string
Implementation
factory ValidatedQuantity.fromString(String string) {
final RegExpMatch? matches = valueRegex.firstMatch(string);
if (matches?.namedGroup('value') == null) {
throw Exception('Quantity must have a number, but was passed $string');
}
string = string.replaceAll(matches!.namedGroup('value')!, '').trim();
if (string.startsWith("'")) {
string = string.substring(1);
}
if (string.endsWith("'")) {
string = string.substring(0, string.length - 1);
}
return ValidatedQuantity(
value: UcumDecimal.fromString(matches.namedGroup('value')),
unit: string.isEmpty ? '1' : string);
}