checkIfTokenFitsRegion function
int
checkIfTokenFitsRegion(
- Map region,
- dynamic token,
- dynamic options
)
Implementation
int checkIfTokenFitsRegion(Map region, token, options) {
bool isDecimal = DECIMALS.contains(token['lowerCaseValue']);
if ((region == {} || region['tokens'].length == 0) && isDecimal) {
return START_NEW_REGION;
}
bool isPunctuation = PUNCTUATION.contains(token['lowerCaseValue']);
if (isPunctuation) return SKIP;
bool isJoiner = JOINERS.contains(token['lowerCaseValue']);
if (isJoiner) return SKIP;
if (isDecimal && !region['hasDecimal']) {
return ADD;
}
bool isNumberWord = NUMBER_WORDS.contains(token['lowerCaseValue']);
if (isNumberWord) {
if (region.isEmpty) return START_NEW_REGION;
if (canAddTokenToEndOfRegion(region, token, impliedHundreds: options)) {
return ADD;
}
return START_NEW_REGION;
}
return NOPE;
}