checkPrefixes method
- bool skip = false,
Check to see if the input begins with either the positive or negative prefixes. Set the gotPositive and gotNegative variables accordingly.
Implementation
void checkPrefixes({bool skip = false}) {
bool checkPrefix(String prefix) =>
prefix.isNotEmpty && input.startsWith(prefix);
// TODO(alanknight): There's a faint possibility of a bug here where
// a positive prefix is followed by a negative prefix that's also a valid
// part of the number, but that seems very unlikely.
if (checkPrefix(_positivePrefix)) gotPositive = true;
if (checkPrefix(_negativePrefix)) gotNegative = true;
// The positive prefix might be a substring of the negative, in
// which case both would match.
if (gotPositive && gotNegative) {
if (_positivePrefix.length > _negativePrefix.length) {
gotNegative = false;
} else if (_negativePrefix.length > _positivePrefix.length) {
gotPositive = false;
}
}
if (skip) {
if (gotPositive) input.pop(_positivePrefix.length);
if (gotNegative) input.pop(_negativePrefix.length);
}
}