@@ -47,6 +47,30 @@ public void skipWhitespaces() {
47
47
while (this .canRead () && Character .isWhitespace (this .peek ())) this .index ++;
48
48
}
49
49
50
+ public int readInt () throws SNbtDeserializeException {
51
+ int start = this .index ;
52
+ while (this .canRead () && this .isNumerical (this .peek ())) this .index ++;
53
+ String number = this .s .substring (start , this .index );
54
+ if (number .isEmpty ()) throw new SNbtDeserializeException ("Expected double but got nothing" , this .s , this .index );
55
+ try {
56
+ return Integer .parseInt (number );
57
+ } catch (NumberFormatException e ) {
58
+ throw new SNbtDeserializeException ("Expected double but got '" + number + "'" , this .s , start );
59
+ }
60
+ }
61
+
62
+ public double readDouble () throws SNbtDeserializeException {
63
+ int start = this .index ;
64
+ while (this .canRead () && this .isNumerical (this .peek ())) this .index ++;
65
+ String number = this .s .substring (start , this .index );
66
+ if (number .isEmpty ()) throw new SNbtDeserializeException ("Expected double but got nothing" , this .s , this .index );
67
+ try {
68
+ return Double .parseDouble (number );
69
+ } catch (NumberFormatException e ) {
70
+ throw new SNbtDeserializeException ("Expected double but got '" + number + "'" , this .s , start );
71
+ }
72
+ }
73
+
50
74
public String readString () throws SNbtDeserializeException {
51
75
this .skipWhitespaces ();
52
76
if (!this .canRead ()) return null ;
@@ -95,6 +119,10 @@ protected boolean isQuote(final char c) {
95
119
return c == '"' ;
96
120
}
97
121
122
+ private boolean isNumerical (final char c ) {
123
+ return c >= '0' && c <= '9' || c == '.' || c == '-' ;
124
+ }
125
+
98
126
private boolean isAlphanumeric (final char c ) {
99
127
return (c >= 'a' && c <= 'z' ) || (c >= 'A' && c <= 'Z' ) || (c >= '0' && c <= '9' ) || c == '_' || c == '-' || c == '.' || c == '+' ;
100
128
}
0 commit comments