@@ -390,16 +390,28 @@ protected boolean hasName(Pattern p, String s) {
390390 private IOException lastException ;
391391
392392 // 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}+");
395395
396396 // A pattern for any token
397397 private static Pattern FIND_ANY_PATTERN = Pattern .compile ("(?s).*" );
398398
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.
402408
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
403415 // Fields and methods to support scanning primitive types
404416
405417 /**
@@ -432,26 +444,32 @@ private static Pattern boolPattern() {
432444 */
433445 private Pattern integerPattern ;
434446 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
437449 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 () );
439451 // \\p{javaDigit} is not guaranteed to be appropriate
440452 // here but what can we do? The final authority will be
441453 // whatever parse method is invoked, so ultimately the
442454 // Scanner will do the right thing
443- String digit = "((?i) [" +radixDigits +"]| \\ p{javaDigit})" ;
455+ String digit = "([" +radixDigits +"])" ; // \\p{javaDigit})";
444456 String groupedNumeral = "(" +non0Digit +digit +"?" +digit +"?(" +
445457 groupSeparator +digit +digit +digit +")+)" ;
446458 // digit++ is the possessive form which is necessary for reducing
447459 // 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+ +")" ;
449466 String javaStyleInteger = "([-+]?(" + numeral + "))" ;
450467 String negativeInteger = negativePrefix + numeral + negativeSuffix ;
451468 String positiveInteger = positivePrefix + numeral + positiveSuffix ;
452- return "(" + javaStyleInteger + ")|(" +
453- positiveInteger + ")|(" +
454- negativeInteger + ")" ;
469+ return "(" + javaStyleInteger + ")"
470+ + "|(" + positiveInteger + ")"
471+ + "|(" + negativeInteger + ")"
472+ ;
455473 }
456474 private Pattern integerPattern () {
457475 if (integerPattern == null ) {
@@ -490,23 +508,31 @@ private static Pattern linePattern() {
490508 private Pattern decimalPattern ;
491509 private void buildFloatAndDecimalPattern () {
492510 // \\p{javaDigit} may not be perfect, see above
493- String digit = "([0-9]|(\\ p{javaDigit}))" ;
511+ String digit = "([0-9])" ; // |(\\p{javaDigit}))";
494512 String exponent = "([eE][+-]?" +digit +"+)?" ;
495- String groupedNumeral = "(" +non0Digit +digit +"?" +digit +"?(" +
513+ String groupedNumeral = "(" +non0Digit +digit +"?" +digit +"?"
514+ + "(" +
496515 groupSeparator +digit +digit +digit +")+)" ;
497516 // 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+ + ")" ;
502527 String nonNumber = "(NaN|" +nanString +"|Infinity|" +
503528 infinityString +")" ;
504529 String positiveFloat = "(" + positivePrefix + decimalNumeral +
505530 positiveSuffix + exponent + ")" ;
506531 String negativeFloat = "(" + negativePrefix + decimalNumeral +
507532 negativeSuffix + exponent + ")" ;
508- String decimal = "(([-+]?" + decimalNumeral + exponent + ")|" +
509- positiveFloat + "|" + negativeFloat + ")" ;
533+ String decimal = "(([-+]?" + decimalNumeral + exponent + ")"
534+ + "|" + positiveFloat + "|" + negativeFloat
535+ + ")" ;
510536 String hexFloat =
511537 "[-+]?0[xX][0-9a-fA-F]*\\ .[0-9a-fA-F]+([pP][-+]?[0-9]+)?" ;
512538 String positiveNonNumber = "(" + positivePrefix + nonNumber +
@@ -516,8 +542,9 @@ private void buildFloatAndDecimalPattern() {
516542 String signedNonNumber = "(([-+]?" +nonNumber +")|" +
517543 positiveNonNumber + "|" +
518544 negativeNonNumber + ")" ;
519- floatPattern = Pattern .compile (decimal + "|" + hexFloat + "|" +
520- signedNonNumber );
545+ floatPattern = Pattern .compile (decimal
546+ + "|" + hexFloat + "|" + signedNonNumber
547+ );
521548 decimalPattern = Pattern .compile (decimal );
522549 }
523550 private Pattern floatPattern () {
@@ -1032,7 +1059,7 @@ private String findPatternInBuffer(Pattern pattern, int horizon) {
10321059 return null ;
10331060 }
10341061 // The match could go away depending on what is next
1035- if (( searchLimit == horizonLimit ) && matcher .requireEnd ()) {
1062+ if (matcher .requireEnd ()) {
10361063 // Rare case: we hit the end of input and it happens
10371064 // that it is at the horizon and the end of input is
10381065 // required for the match.
@@ -2275,24 +2302,25 @@ private String processFloatToken(String token) {
22752302 if (isNegative )
22762303 result = "-" + result ;
22772304
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+ // }
22962324
22972325 return result ;
22982326 }
@@ -2629,4 +2657,5 @@ public Scanner reset() {
26292657 clearCaches ();
26302658 return this ;
26312659 }
2660+
26322661}
0 commit comments