Skip to content

Commit

Permalink
Fix JsonReader parser to support number E notation
Browse files Browse the repository at this point in the history
  • Loading branch information
afrankvt committed Jun 16, 2021
1 parent b3ee115 commit 420f63a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion novant/novant-rt/src/io/novant/util/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private Double readNum() throws IOException
{
StringBuffer buf = new StringBuffer();
if (peek == '-') buf.append((char)read());
while (Character.isDigit(peek) || peek == '.') buf.append((char)read());
while (Character.isDigit(peek) || peek == '.' || peek == 'E' || peek == '-')
buf.append((char)read());
return Double.parseDouble(buf.toString());
}

Expand Down
12 changes: 7 additions & 5 deletions novant/novant-rt/srcTest/test/io/novant/BJsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public class BJsonTest extends BTestNg

@Test public void testNum() throws IOException
{
verifyEq(read("5"), new Double(5));
verifyEq(read("-12"), new Double(-12));
verifyEq(read("10572"), new Double(10572));
verifyEq(read("18.4"), new Double(18.4));
verifyEq(read("-0.123"), new Double(-0.123));
verifyEq(read("5"), new Double(5));
verifyEq(read("-12"), new Double(-12));
verifyEq(read("10572"), new Double(10572));
verifyEq(read("18.4"), new Double(18.4));
verifyEq(read("-0.123"), new Double(-0.123));
verifyEq(read("2.351E8"), new Double(2.351E8));
verifyEq(read("6.195E-4"), new Double(6.195E-4));
}

@Test public void testStr() throws IOException
Expand Down

0 comments on commit 420f63a

Please sign in to comment.