Skip to content

Commit 4caffa8

Browse files
authored
Merge pull request #192 from BobHanson/hanson1
Hanson1
2 parents b7229d8 + c2239a7 commit 4caffa8

File tree

14 files changed

+2502
-132
lines changed

14 files changed

+2502
-132
lines changed
908 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201203173354
1+
20201205151557
908 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201203173354
1+
20201205151557
908 Bytes
Binary file not shown.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package java.util;
27+
28+
/**
29+
* Thrown by a <code>Scanner</code> to indicate that the token
30+
* retrieved does not match the pattern for the expected type, or
31+
* that the token is out of range for the expected type.
32+
*
33+
* @author unascribed
34+
* @see java.util.Scanner
35+
* @since 1.5
36+
*/
37+
public
38+
class InputMismatchException extends NoSuchElementException {
39+
private static final long serialVersionUID = 8811230760997066428L;
40+
41+
/**
42+
* Constructs an <code>InputMismatchException</code> with <tt>null</tt>
43+
* as its error message string.
44+
*/
45+
public InputMismatchException() {
46+
super();
47+
}
48+
49+
/**
50+
* Constructs an <code>InputMismatchException</code>, saving a reference
51+
* to the error message string <tt>s</tt> for later retrieval by the
52+
* <tt>getMessage</tt> method.
53+
*
54+
* @param s the detail message.
55+
*/
56+
public InputMismatchException(String s) {
57+
super(s);
58+
}
59+
}

sources/net.sf.j2s.java.core/src/java/util/Scanner.java

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)