[PATCH] WST-Parser: Improve handling of line-endings

Wald Commits scm-commit at wald.intevation.org
Thu Oct 31 13:11:07 CET 2013


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1383221463 -3600
# Node ID 2a2e89c015887679cbace0a94c709dcf7bc4deaa
# Parent  1c365fa9d5a1a58d145ebf5d12e445584193a4db
WST-Parser: Improve handling of line-endings.

diff -r 1c365fa9d5a1 -r 2a2e89c01588 backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java
--- 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;
         }
 


More information about the Dive4elements-commits mailing list