comparison backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java @ 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 450582bcad75
children bdb12632c5f5
comparison
equal deleted inserted replaced
7479:1c365fa9d5a1 7480:2a2e89c01588
379 ) { 379 ) {
380 lsBezeichner[j] = input.substring( 380 lsBezeichner[j] = input.substring(
381 i, i+colNaWidths[j]).trim(); 381 i, i+colNaWidths[j]).trim();
382 } 382 }
383 } 383 }
384 else { 384 else { // fetch column names from non-comment header line
385 // (above first Qs)
385 // first column begins at position 8 in line 386 // first column begins at position 8 in line
386 for (int i = 8, col = 0; i < input.length(); i += 9) { 387 for (int i = 8, col = 0; i < input.length(); i += 9) {
387 if ((i + 9) > input.length()) { 388 // one column header is 9 chars wide
388 i = input.length() - 10; 389 // but the last one may be shorter
390 if (col < lsBezeichner.length) {
391 lsBezeichner[col++] =
392 input.substring(i,
393 Math.min(i + 9, input.length())).trim();
389 } 394 }
390 // one column header is 9 chars wide
391 lsBezeichner[col++] =
392 input.substring(i, i + 9).trim();
393
394 if (col == lsBezeichner.length) { 395 if (col == lsBezeichner.length) {
395 break; 396 break;
396 } 397 }
397 } 398 }
398 } 399 }
528 strings.add(line.substring(0, 8)); 529 strings.add(line.substring(0, 8));
529 } 530 }
530 531
531 int pos = 9; 532 int pos = 9;
532 for (int i = 0; i < tokenCount; ++i) { 533 for (int i = 0; i < tokenCount; ++i) {
533 if (line.length() >= pos + 8) { 534 strings.add(line.substring(pos,
534 strings.add(line.substring(pos, pos + 8)); 535 Math.min(pos + 8, line.length())));
535 }
536 else {
537 strings.add("");
538 }
539 pos += 9; 536 pos += 9;
540 } 537 }
541 538
542 return strings.toArray(new String[strings.size()]); 539 return strings.toArray(new String[strings.size()]);
543 } 540 }

http://dive4elements.wald.intevation.org