Mercurial > hg > monetdb-java
changeset 116:04c535b05c52
Fixed negative number parsing on the StartOfHeaderParser
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Thu, 16 Feb 2017 11:07:55 +0100 (2017-02-16) |
parents | 8d81506399d1 |
children | a030c3e53cf5 |
files | src/main/java/nl/cwi/monetdb/mcl/parser/HeaderLineParser.java src/main/java/nl/cwi/monetdb/mcl/parser/StartOfHeaderParser.java |
diffstat | 2 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/mcl/parser/HeaderLineParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/parser/HeaderLineParser.java @@ -157,6 +157,10 @@ public class HeaderLineParser extends MC * Returns an array of ints containing the values between * ',\t' separators. * + * Feb2017 note - This integer parser doesn't have to parse negative + * numbers, because it is only used to parse column lengths + * which is always greater than 0. + * * @param chrLine a character array holding the input data * @param start where the relevant data starts * @param stop where the relevant data stops @@ -171,7 +175,6 @@ public class HeaderLineParser extends MC if (chrLine[i] == ',' && chrLine[i + 1] == '\t') { intValues[elem++] = tmp; tmp = 0; - start = i++; } else { tmp *= 10; // note: don't use Character.isDigit() here, because
--- a/src/main/java/nl/cwi/monetdb/mcl/parser/StartOfHeaderParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/parser/StartOfHeaderParser.java @@ -96,15 +96,18 @@ public class StartOfHeaderParser { * @throws MCLParseException if no numeric value could be read */ public final int getNextAsInt() throws MCLParseException { + boolean positive = true; pos++; if (!soh.hasRemaining()) throw new MCLParseException("unexpected end of string", soh.position() - 1); - int tmp; + int tmp = 0; char chr = soh.get(); // note: don't use Character.isDigit() here, because // we only want ISO-LATIN-1 digits if (chr >= '0' && chr <= '9') { tmp = (int)chr - (int)'0'; + } else if(chr == '-') { + positive = false; } else { throw new MCLParseException("expected a digit", soh.position() - 1); } @@ -118,7 +121,7 @@ public class StartOfHeaderParser { } } - return tmp; + return positive ? tmp : -tmp; } public final String getNextAsString() throws MCLParseException {