removeColumn method

int removeColumn(
  1. String inFieldName
)

Remove a column from this DbaseFileHeader.

@todo This is really ugly, don't know who wrote it, but it needs fixing... @param inFieldName The name of the field, will ignore case and trim. @return index of the removed column, -1 if no found

Implementation

int removeColumn(String inFieldName) {
  var retCol = -1;
  var tempLength = 1;
  var tempFieldDescriptors =
      <DbaseField>[]; //List<DbaseField>(fields.length - 1);
  for (var i = 0, j = 0; i < fields.length; i++) {
    if (!StringUtilities.equalsIgnoreCase(
        inFieldName, fields[i].fieldName.trim())) {
      // if this is the last field and we still haven't found the
      // named field
      if (i == j && i == fields.length - 1) {
        ShpLogger().w('Could not find a field named '
            ' + inFieldName + '
            ' for removal');
        return retCol;
      }

      tempFieldDescriptors.add(fields[i]);
      tempFieldDescriptors[j].fieldDataAddress = tempLength;
      tempLength += tempFieldDescriptors[j].fieldLength;
      // tempFieldDescriptors[j] = fields[i];
      // tempFieldDescriptors[j].fieldDataAddress = tempLength;
      // tempLength += tempFieldDescriptors[j].fieldLength;
      // only increment j on non-matching fields
      j++;
    } else {
      retCol = i;
    }
  }

  // set the fields.
  fields = tempFieldDescriptors;
  headerLength = 33 + 32 * fields.length;
  recordLength = tempLength;

  return retCol;
}