in gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/text/SortAction.java [255:287]
protected List<Integer> getFieldIndexes(String o) {
List<Integer> fields = new ArrayList<Integer>();
if (o.length() > 0) {
if (separator == '\0') {
int i = 0;
fields.add(0);
for (int idx = 1; idx < o.length(); idx++) {
if (Character.isWhitespace(o.charAt(idx)) && !Character.isWhitespace(o.charAt(idx - 1))) {
fields.add(idx - 1);
fields.add(idx);
}
}
fields.add(o.length() - 1);
} else {
int last = -1;
for (int idx = o.indexOf(separator); idx >= 0; idx = o.indexOf(separator, idx + 1)) {
if (last >= 0) {
fields.add(last);
fields.add(idx - 1);
} else if (idx > 0) {
fields.add(0);
fields.add(idx - 1);
}
last = idx + 1;
}
if (last < o.length()) {
fields.add(last < 0 ? 0 : last);
fields.add(o.length() - 1);
}
}
}
return fields;
}