|
44 | 44 | */
|
45 | 45 | public class PathParser
|
46 | 46 | {
|
| 47 | + /* |
| 48 | + * This was part of NumberCharState. Unfortunately, it is not inlined as of Java 20. Maybe when Java has value |
| 49 | + * classes this will change. |
| 50 | + */ |
| 51 | + int iteration = 0; |
| 52 | + boolean dotAllowed = true; |
| 53 | + boolean signAllowed = true; |
| 54 | + boolean exponentAllowed = true; |
| 55 | + /* End NumberCharState class information */ |
| 56 | + |
47 | 57 | private final String input;
|
48 | 58 | private final int inputLength;
|
49 | 59 | private int index;
|
@@ -82,7 +92,7 @@ private boolean hasNext()
|
82 | 92 | // This only checks for the rough structure of a number as we need to know
|
83 | 93 | // when to separate the next token.
|
84 | 94 | // Explicit parsing is done by Float#parseFloat.
|
85 |
| - private boolean isValidNumberChar(char c, NumberCharState state) |
| 95 | + private boolean isValidNumberChar(char c, PathParser state) |
86 | 96 | {
|
87 | 97 | boolean valid = '0' <= c && c <= '9';
|
88 | 98 | if (valid && state.iteration == 1 && input.charAt(index - 1) == '0')
|
@@ -121,7 +131,7 @@ private void consumeWhiteSpaceOrSeparator() {
|
121 | 131 | private float nextFloat()
|
122 | 132 | {
|
123 | 133 | int start = index;
|
124 |
| - NumberCharState state = new NumberCharState(); |
| 134 | + PathParser state = this.resetNumberCharState(); |
125 | 135 | while (hasNext() && isValidNumberChar(peek(), state)) {
|
126 | 136 | consume();
|
127 | 137 | }
|
@@ -241,11 +251,15 @@ public PathCommand[] parsePathCommand()
|
241 | 251 | return commands.toArray(new PathCommand[0]);
|
242 | 252 | }
|
243 | 253 |
|
244 |
| - private static class NumberCharState |
245 |
| - { |
246 |
| - int iteration = 0; |
247 |
| - boolean dotAllowed = true; |
248 |
| - boolean signAllowed = true; |
249 |
| - boolean exponentAllowed = true; |
| 254 | + /** |
| 255 | + * Reset the NumberCharState |
| 256 | + * @return {this}, for ease of changing back to a NumberCharState class later. |
| 257 | + */ |
| 258 | + private PathParser resetNumberCharState() { |
| 259 | + this.iteration = 0; |
| 260 | + this.dotAllowed = true; |
| 261 | + this.signAllowed = true; |
| 262 | + this.exponentAllowed = true; |
| 263 | + return this; |
250 | 264 | }
|
251 | 265 | }
|
0 commit comments