Mercurial > hg > monetdb-java
diff src/main/java/nl/cwi/monetdb/mcl/parser/StartOfHeaderParser.java @ 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 | b9b35ca2eec2 |
children | a030c3e53cf5 |
line wrap: on
line diff
--- 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 {