@@ -390,16 +390,28 @@ protected boolean hasName(Pattern p, String s) {
390
390
private IOException lastException ;
391
391
392
392
// A pattern for java whitespace
393
- private static Pattern WHITESPACE_PATTERN = Pattern .compile (
394
- "\\ p{javaWhitespace}+" );
393
+ private static Pattern WHITESPACE_PATTERN = Pattern .compile (" \\ s+" );
394
+ // "\\p{javaWhitespace}+");
395
395
396
396
// A pattern for any token
397
397
private static Pattern FIND_ANY_PATTERN = Pattern .compile ("(?s).*" );
398
398
399
- // A pattern for non-ASCII digits
400
- private static Pattern NON_ASCII_DIGIT = Pattern .compile (
401
- "[\\ p{javaDigit}&&[^0-9]]" );
399
+ // Some Unicode character ranges that contain digits:
400
+ //
401
+ // '\u0030' through '\u0039', ISO-LATIN-1 digits ('0' through '9')
402
+ // '\u0660' through '\u0669', Arabic-Indic digits
403
+ // '\u06F0' through '\u06F9', Extended Arabic-Indic digits
404
+ // '\u0966' through '\u096F', Devanagari digits
405
+ // '\uFF10' through '\uFF19', Fullwidth digits
406
+
407
+ // Many other character ranges contain digits as well.
402
408
409
+ // A pattern for non-ASCII digits
410
+ // SwingJS not supported
411
+ // private static Pattern NON_ASCII_DIGIT = Pattern.compile(
412
+ // //"[\\p{javaDigit}&&[^0-9]]");
413
+ // "[\\p{javaDigit}&&[^0-9]]");
414
+ // A pattern for java whitespace
403
415
// Fields and methods to support scanning primitive types
404
416
405
417
/**
@@ -432,26 +444,32 @@ private static Pattern boolPattern() {
432
444
*/
433
445
private Pattern integerPattern ;
434
446
private String digits = "0123456789abcdefghijklmnopqrstuvwxyz" ;
435
- private String non0Digit = "[\\ p{javaDigit}&&[^0]]" ;
436
- private int SIMPLE_GROUP_INDEX = 5 ;
447
+ private String non0Digit = "[1-9]" ; //"[ \\p{javaDigit}&&[^0]]";
448
+ private int SIMPLE_GROUP_INDEX = 12 ; // SwingJS - moved simple to later
437
449
private String buildIntegerPatternString () {
438
- String radixDigits = digits .substring (0 , radix );
450
+ String radixDigits = ( radix == 10 ? "0-9" : digits .substring (0 , radix ) + digits . substring ( 10 , radix ). toUpperCase () );
439
451
// \\p{javaDigit} is not guaranteed to be appropriate
440
452
// here but what can we do? The final authority will be
441
453
// whatever parse method is invoked, so ultimately the
442
454
// Scanner will do the right thing
443
- String digit = "((?i) [" +radixDigits +"]| \\ p{javaDigit})" ;
455
+ String digit = "([" +radixDigits +"])" ; // \\p{javaDigit})";
444
456
String groupedNumeral = "(" +non0Digit +digit +"?" +digit +"?(" +
445
457
groupSeparator +digit +digit +digit +")+)" ;
446
458
// digit++ is the possessive form which is necessary for reducing
447
459
// backtracking that would otherwise cause unacceptable performance
448
- String numeral = "((" + digit +"++)|" +groupedNumeral +")" ;
460
+ // JavaScript requires reversal of these two
461
+ String numeral = "("
462
+ +groupedNumeral
463
+ + "|"
464
+ + "(" + digit +"+)"
465
+ +")" ;
449
466
String javaStyleInteger = "([-+]?(" + numeral + "))" ;
450
467
String negativeInteger = negativePrefix + numeral + negativeSuffix ;
451
468
String positiveInteger = positivePrefix + numeral + positiveSuffix ;
452
- return "(" + javaStyleInteger + ")|(" +
453
- positiveInteger + ")|(" +
454
- negativeInteger + ")" ;
469
+ return "(" + javaStyleInteger + ")"
470
+ + "|(" + positiveInteger + ")"
471
+ + "|(" + negativeInteger + ")"
472
+ ;
455
473
}
456
474
private Pattern integerPattern () {
457
475
if (integerPattern == null ) {
@@ -490,23 +508,31 @@ private static Pattern linePattern() {
490
508
private Pattern decimalPattern ;
491
509
private void buildFloatAndDecimalPattern () {
492
510
// \\p{javaDigit} may not be perfect, see above
493
- String digit = "([0-9]|(\\ p{javaDigit}))" ;
511
+ String digit = "([0-9])" ; // |(\\p{javaDigit}))";
494
512
String exponent = "([eE][+-]?" +digit +"+)?" ;
495
- String groupedNumeral = "(" +non0Digit +digit +"?" +digit +"?(" +
513
+ String groupedNumeral = "(" +non0Digit +digit +"?" +digit +"?"
514
+ + "(" +
496
515
groupSeparator +digit +digit +digit +")+)" ;
497
516
// Once again digit++ is used for performance, as above
498
- String numeral = "((" +digit +"++)|" +groupedNumeral +")" ;
499
- String decimalNumeral = "(" +numeral +"|" +numeral +
500
- decimalSeparator + digit + "*+|" + decimalSeparator +
501
- digit + "++)" ;
517
+ String numeral = "("
518
+ + "(" +digit +"+)"
519
+ + "|" +groupedNumeral
520
+ +")" ;
521
+ // SwingJS had to move numeral to the end here
522
+ String decimalNumeral = "("
523
+ +numeral + decimalSeparator + digit + "*"
524
+ + "|" + decimalSeparator + digit + "+"
525
+ + "|" +numeral
526
+ + ")" ;
502
527
String nonNumber = "(NaN|" +nanString +"|Infinity|" +
503
528
infinityString +")" ;
504
529
String positiveFloat = "(" + positivePrefix + decimalNumeral +
505
530
positiveSuffix + exponent + ")" ;
506
531
String negativeFloat = "(" + negativePrefix + decimalNumeral +
507
532
negativeSuffix + exponent + ")" ;
508
- String decimal = "(([-+]?" + decimalNumeral + exponent + ")|" +
509
- positiveFloat + "|" + negativeFloat + ")" ;
533
+ String decimal = "(([-+]?" + decimalNumeral + exponent + ")"
534
+ + "|" + positiveFloat + "|" + negativeFloat
535
+ + ")" ;
510
536
String hexFloat =
511
537
"[-+]?0[xX][0-9a-fA-F]*\\ .[0-9a-fA-F]+([pP][-+]?[0-9]+)?" ;
512
538
String positiveNonNumber = "(" + positivePrefix + nonNumber +
@@ -516,8 +542,9 @@ private void buildFloatAndDecimalPattern() {
516
542
String signedNonNumber = "(([-+]?" +nonNumber +")|" +
517
543
positiveNonNumber + "|" +
518
544
negativeNonNumber + ")" ;
519
- floatPattern = Pattern .compile (decimal + "|" + hexFloat + "|" +
520
- signedNonNumber );
545
+ floatPattern = Pattern .compile (decimal
546
+ + "|" + hexFloat + "|" + signedNonNumber
547
+ );
521
548
decimalPattern = Pattern .compile (decimal );
522
549
}
523
550
private Pattern floatPattern () {
@@ -1032,7 +1059,7 @@ private String findPatternInBuffer(Pattern pattern, int horizon) {
1032
1059
return null ;
1033
1060
}
1034
1061
// The match could go away depending on what is next
1035
- if (( searchLimit == horizonLimit ) && matcher .requireEnd ()) {
1062
+ if (matcher .requireEnd ()) {
1036
1063
// Rare case: we hit the end of input and it happens
1037
1064
// that it is at the horizon and the end of input is
1038
1065
// required for the match.
@@ -2275,24 +2302,25 @@ private String processFloatToken(String token) {
2275
2302
if (isNegative )
2276
2303
result = "-" + result ;
2277
2304
2278
- // Translate non-ASCII digits
2279
- Matcher m = NON_ASCII_DIGIT .matcher (result );
2280
- if (m .find ()) {
2281
- StringBuilder inASCII = new StringBuilder ();
2282
- for (int i =0 ; i <result .length (); i ++) {
2283
- char nextChar = result .charAt (i );
2284
- if (Character .isDigit (nextChar )) {
2285
- int d = Character .digit (nextChar , 10 );
2286
- if (d != -1 )
2287
- inASCII .append (d );
2288
- else
2289
- inASCII .append (nextChar );
2290
- } else {
2291
- inASCII .append (nextChar );
2292
- }
2293
- }
2294
- result = inASCII .toString ();
2295
- }
2305
+ // swingjs NOT IMPLEMENTED
2306
+ // // Translate non-ASCII digits
2307
+ // Matcher m = NON_ASCII_DIGIT.matcher(result);
2308
+ // if (m.find()) {
2309
+ // StringBuilder inASCII = new StringBuilder();
2310
+ // for (int i=0; i<result.length(); i++) {
2311
+ // char nextChar = result.charAt(i);
2312
+ // if (Character.isDigit(nextChar)) {
2313
+ // int d = Character.digit(nextChar, 10);
2314
+ // if (d != -1)
2315
+ // inASCII.append(d);
2316
+ // else
2317
+ // inASCII.append(nextChar);
2318
+ // } else {
2319
+ // inASCII.append(nextChar);
2320
+ // }
2321
+ // }
2322
+ // result = inASCII.toString();
2323
+ // }
2296
2324
2297
2325
return result ;
2298
2326
}
@@ -2629,4 +2657,5 @@ public Scanner reset() {
2629
2657
clearCaches ();
2630
2658
return this ;
2631
2659
}
2660
+
2632
2661
}
0 commit comments