4
4
import java .io .Reader ;
5
5
import java .util .Objects ;
6
6
import java .util .Spliterators ;
7
- import java .util .function .BiFunction ;
7
+ import java .util .concurrent .atomic .AtomicBoolean ;
8
+ import java .util .concurrent .atomic .AtomicInteger ;
8
9
import java .util .function .Consumer ;
10
+ import java .util .function .Function ;
9
11
import java .util .stream .Stream ;
10
12
import java .util .stream .StreamSupport ;
11
13
@@ -211,31 +213,36 @@ public Token nextToken() throws IOException {
211
213
if (isEof (ch )) {
212
214
return null ;
213
215
}
214
- int oldch = -1 ;
215
- BiFunction <Integer , Integer , Boolean > isValid = (c , oldc ) -> false ;
216
+ Function <Integer , Boolean > isValid = (c ) -> false ;
216
217
Type nextState = null ;
217
218
if (state == null ) {
218
219
if (isCommentChar (ch )) {
219
220
state = Type .COMMENT ;
220
- isValid = (c , oldc ) -> !isEol (c ) && !isEof (c );
221
- } else if (isWhitespaceChar (ch )) {
221
+ isValid = (c ) -> !isEol (c ) && !isEof (c );
222
+ } else if (isWhitespaceEolChar (ch )) {
222
223
state = Type .WHITESPACE ;
223
- isValid = (c , oldc ) -> isWhitespaceChar (c ) && !isEol (oldc );
224
+ final AtomicInteger oldc = new AtomicInteger (-1 );
225
+ isValid = (c ) -> isWhitespaceEolChar (c ) && !isEol (oldc .getAndSet (c ));
224
226
} else {
225
227
state = Type .KEY ;
226
- isValid = (c , oldc ) -> !isSeparatorChar (c );
228
+ isValid =
229
+ (c ) ->
230
+ !isSeparatorChar (c )
231
+ && !isWhitespaceChar (c )
232
+ && !isEol (c )
233
+ && !isEof (c );
227
234
nextState = Type .SEPARATOR ;
228
235
}
229
236
} else if (state == Type .SEPARATOR ) {
230
- isValid = (c , oldc ) -> isSeparatorChar (c );
237
+ final AtomicBoolean once = new AtomicBoolean (true );
238
+ isValid = (c ) -> isWhitespaceChar (c ) || (isSeparatorChar (c ) && once .getAndSet (false ));
231
239
nextState = Type .VALUE ;
232
240
} else if (state == Type .VALUE ) {
233
- isValid = (c , oldc ) -> !isEol (c ) && !isEof (c );
241
+ isValid = (c ) -> !isEol (c ) && !isEof (c );
234
242
}
235
243
while (true ) {
236
- if (isValid .apply (ch , oldch )) {
244
+ if (isValid .apply (ch )) {
237
245
addChar (readChar ());
238
- oldch = ch ;
239
246
ch = peekChar ();
240
247
} else {
241
248
String text = string ();
@@ -336,8 +343,7 @@ static String unescape(String escape) {
336
343
case '\n' :
337
344
// Skip any leading whitespace
338
345
while (i < (escape .length () - 1 )
339
- && isWhitespaceChar (ch = escape .charAt (i + 1 ))
340
- && !isEol (ch )) {
346
+ && isWhitespaceChar (ch = escape .charAt (i + 1 ))) {
341
347
i ++;
342
348
}
343
349
break ;
@@ -353,11 +359,15 @@ && isWhitespaceChar(ch = escape.charAt(i + 1))
353
359
}
354
360
355
361
private static boolean isSeparatorChar (int ch ) {
356
- return ch == ' ' || ch == '\t' || ch == ' =' || ch == ':' ;
362
+ return ch == '=' || ch == ':' ;
357
363
}
358
364
359
365
private static boolean isWhitespaceChar (int ch ) {
360
- return ch == ' ' || ch == '\t' || ch == '\f' || isEol (ch );
366
+ return ch == ' ' || ch == '\t' || ch == '\f' ;
367
+ }
368
+
369
+ private static boolean isWhitespaceEolChar (int ch ) {
370
+ return isWhitespaceChar (ch ) || isEol (ch );
361
371
}
362
372
363
373
private static boolean isCommentChar (int ch ) {
0 commit comments