package tim.prune.load;
-import tim.prune.I18nManager;
-import tim.prune.data.Field;
-
/**
* Class responsible for splitting the file contents into an array
* based on the selected delimiter character
private int _numRows = 0;
private int _numColumns = 0;
private boolean[] _columnStates = null;
+ private String[] _firstFullRow = null;
+
/**
* Constructor
*/
public String[][] splitFieldData(char inDelim)
{
+ _firstFullRow = null;
if (_cacher == null) return null;
String[] contents = _cacher.getContents();
if (contents == null || contents.length == 0) return null;
- String delimStr = "" + inDelim;
+ String delimStr = checkDelimiter(inDelim);
// Count non-blank rows and max field count
_numRows = 0;
int maxFields = 0;
if (splitLine != null && splitLine.length > maxFields)
{
maxFields = splitLine.length;
+ _firstFullRow = splitLine;
}
}
}
result[i] = new String[maxFields];
if (contents[i] != null)
{
- String wholeLine = contents[i].trim();
- if (!wholeLine.equals(""))
+ String wholeLine = contents[i];
+ if (!wholeLine.trim().equals(""))
{
+ // Don't use trimmed string here because you'll lose empty fields at beginning
+ // if separated by spaces or tabs
String[] splitLine = wholeLine.split(delimStr);
if (splitLine != null)
{
return _numColumns;
}
+ /**
+ * @return the fields in the first full row
+ */
+ public String[] getFirstFullRow()
+ {
+ return _firstFullRow;
+ }
+
/**
* Check if the specified column of the data is blank
return !_columnStates[inColumnNum];
}
-
/**
- * @return a Field array to use as defaults for the data
+ * Check the delimiter for proper regular expression matching
+ * @param inDelim character selected as delimiter
+ * @return regular expression for splitting
*/
- public Field[] makeDefaultFields()
+ private static String checkDelimiter(char inDelim)
{
- Field[] fields = null;
- if (_numColumns > 0)
- {
- fields = new Field[_numColumns];
- try
- {
- fields[0] = Field.LATITUDE;
- fields[1] = Field.LONGITUDE;
- fields[2] = Field.ALTITUDE;
- fields[3] = Field.WAYPT_NAME;
- fields[4] = Field.WAYPT_TYPE;
- String customPrefix = I18nManager.getText("fieldname.prefix") + " ";
- for (int i=5;; i++)
- {
- fields[i] = new Field(customPrefix + (i+1));
- }
- }
- catch (ArrayIndexOutOfBoundsException finished)
- {
- // Finished populating array
- }
+ String result = "" + inDelim;
+ // Don't pass asterisks or dots without escaping them for RE
+ if (inDelim == '*' || inDelim == '.') {
+ result = "\\" + result;
}
- else
- fields = new Field[0];
- return fields;
+ return result;
}
}