checkIfTokenFitsRegion function

int checkIfTokenFitsRegion(
  1. Map region,
  2. dynamic token,
  3. 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;
}