getSubRegions function

List getSubRegions(
  1. Map region,
  2. dynamic options
)

Implementation

List getSubRegions(Map region, options) {
  var subRegions = [];
  var currentSubRegion;
  int tokensCount = region['tokens'].length;
  int i = tokensCount - 1;
  while (i >= 0) {
    final token = region['tokens'][i];
    Map checkIfTokenFitsSubR =
        checkIfTokenFitsSubRegion(currentSubRegion, token, options);
    var type = checkIfTokenFitsSubR['type'];
    var action = checkIfTokenFitsSubR['action'];
    bool isHundred = checkIfTokenFitsSubR['isHundred'];
    token['type'] = isHundred ? TOKEN_TYPE['HUNDRED'] : token['type'];
    switch (action) {
      case ADD:
        {
          currentSubRegion['type'] = type;
          currentSubRegion['tokens'].insert(0, token);
          break;
        }
      case START_NEW_REGION:
        {
          currentSubRegion = {
            'tokens': [token],
            'type': type
          };
          subRegions.insert(0, currentSubRegion);
          break;
        }
    }
    i--;
  }
  return subRegions;
}