Skip to content

Commit

Permalink
Fixed Number Parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed May 30, 2021
1 parent b3f0950 commit fa15d96
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public NbtByteArray readTagByteArray() throws IOException {

public NbtString readTagString() throws IOException {
String input = readString();
if (Strings.isNumeric(input)) {
if (!input.isEmpty() && Strings.isNumeric(input)) {
return new NbtBigInt(input);
}
return new NbtString(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ protected boolean isNumber() throws IOException {
cursor += 1;
return true;
}
int length = (decimal ? stringBuffer.split(".", 2)[0].length() : stringBuffer.length()) - (negative ? 0 : 1);
int length = (decimal ? stringBuffer.split(".", 2)[0].length() : stringBuffer.length()) - (negative ? 1 : 0);

if (decimal) {
if (exponential && exponentialValue.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.syntaxphoenix.syntaxapi.test.json;

import java.io.IOException;

import org.junit.jupiter.api.Test;

import com.syntaxphoenix.syntaxapi.json.JsonEntry;
import com.syntaxphoenix.syntaxapi.json.JsonObject;
import com.syntaxphoenix.syntaxapi.json.ValueType;
import com.syntaxphoenix.syntaxapi.json.io.JsonParser;
import com.syntaxphoenix.syntaxapi.utils.java.lang.StringBuilder;

public class JsonObjectTest {
Expand Down Expand Up @@ -55,4 +58,27 @@ public void testObjectHas() {

}

@Test
public void testNumberParse() throws IOException {

System.out.println("\n== Number Parse Test ==\n");

JsonObject object = new JsonObject();
object.set("short", Byte.MAX_VALUE + 1);
object.set("long", Integer.MAX_VALUE + 1);
object.set("double", Float.MAX_VALUE + 1);

String out = object.toString();
JsonParser parser = new JsonParser();
JsonObject val = (JsonObject) parser.fromString(out);

System.out.println(val.get("short").getValue());
System.out.println(val.get("long").getValue());
System.out.println(val.get("double").getValue());
System.out.println();

System.out.println("== Object Parse Test ==");

}

}

0 comments on commit fa15d96

Please sign in to comment.