Mercurial > dive4elements > river
changeset 7480:2a2e89c01588
WST-Parser: Improve handling of line-endings.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 31 Oct 2013 13:11:03 +0100 |
parents | 1c365fa9d5a1 |
children | bdb12632c5f5 f8e1af4e2f69 |
files | backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java |
diffstat | 1 files changed, 10 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java Thu Oct 31 11:56:45 2013 +0100 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java Thu Oct 31 13:11:03 2013 +0100 @@ -381,16 +381,17 @@ i, i+colNaWidths[j]).trim(); } } - else { + else { // fetch column names from non-comment header line + // (above first Qs) // first column begins at position 8 in line for (int i = 8, col = 0; i < input.length(); i += 9) { - if ((i + 9) > input.length()) { - i = input.length() - 10; + // one column header is 9 chars wide + // but the last one may be shorter + if (col < lsBezeichner.length) { + lsBezeichner[col++] = + input.substring(i, + Math.min(i + 9, input.length())).trim(); } - // one column header is 9 chars wide - lsBezeichner[col++] = - input.substring(i, i + 9).trim(); - if (col == lsBezeichner.length) { break; } @@ -530,12 +531,8 @@ int pos = 9; for (int i = 0; i < tokenCount; ++i) { - if (line.length() >= pos + 8) { - strings.add(line.substring(pos, pos + 8)); - } - else { - strings.add(""); - } + strings.add(line.substring(pos, + Math.min(pos + 8, line.length()))); pos += 9; }