Thanks to visit codestin.com
Credit goes to github.com

Skip to content

java.util.Scanner #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20201203173354
20201205151557
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20201203173354
20201205151557
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.util;

/**
* Thrown by a <code>Scanner</code> to indicate that the token
* retrieved does not match the pattern for the expected type, or
* that the token is out of range for the expected type.
*
* @author unascribed
* @see java.util.Scanner
* @since 1.5
*/
public
class InputMismatchException extends NoSuchElementException {
private static final long serialVersionUID = 8811230760997066428L;

/**
* Constructs an <code>InputMismatchException</code> with <tt>null</tt>
* as its error message string.
*/
public InputMismatchException() {
super();
}

/**
* Constructs an <code>InputMismatchException</code>, saving a reference
* to the error message string <tt>s</tt> for later retrieval by the
* <tt>getMessage</tt> method.
*
* @param s the detail message.
*/
public InputMismatchException(String s) {
super(s);
}
}
113 changes: 71 additions & 42 deletions sources/net.sf.j2s.java.core/src/java/util/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,28 @@ protected boolean hasName(Pattern p, String s) {
private IOException lastException;

// A pattern for java whitespace
private static Pattern WHITESPACE_PATTERN = Pattern.compile(
"\\p{javaWhitespace}+");
private static Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");
// "\\p{javaWhitespace}+");

// A pattern for any token
private static Pattern FIND_ANY_PATTERN = Pattern.compile("(?s).*");

// A pattern for non-ASCII digits
private static Pattern NON_ASCII_DIGIT = Pattern.compile(
"[\\p{javaDigit}&&[^0-9]]");
// Some Unicode character ranges that contain digits:
//
// '\u0030' through '\u0039', ISO-LATIN-1 digits ('0' through '9')
// '\u0660' through '\u0669', Arabic-Indic digits
// '\u06F0' through '\u06F9', Extended Arabic-Indic digits
// '\u0966' through '\u096F', Devanagari digits
// '\uFF10' through '\uFF19', Fullwidth digits

// Many other character ranges contain digits as well.

// A pattern for non-ASCII digits
// SwingJS not supported
// private static Pattern NON_ASCII_DIGIT = Pattern.compile(
// //"[\\p{javaDigit}&&[^0-9]]");
// "[\\p{javaDigit}&&[^0-9]]");
// A pattern for java whitespace
// Fields and methods to support scanning primitive types

/**
Expand Down Expand Up @@ -432,26 +444,32 @@ private static Pattern boolPattern() {
*/
private Pattern integerPattern;
private String digits = "0123456789abcdefghijklmnopqrstuvwxyz";
private String non0Digit = "[\\p{javaDigit}&&[^0]]";
private int SIMPLE_GROUP_INDEX = 5;
private String non0Digit = "[1-9]";//"[\\p{javaDigit}&&[^0]]";
private int SIMPLE_GROUP_INDEX = 12; // SwingJS - moved simple to later
private String buildIntegerPatternString() {
String radixDigits = digits.substring(0, radix);
String radixDigits = (radix == 10 ? "0-9" : digits.substring(0, radix) + digits.substring(10, radix).toUpperCase());
// \\p{javaDigit} is not guaranteed to be appropriate
// here but what can we do? The final authority will be
// whatever parse method is invoked, so ultimately the
// Scanner will do the right thing
String digit = "((?i)["+radixDigits+"]|\\p{javaDigit})";
String digit = "(["+radixDigits+"])";//\\p{javaDigit})";
String groupedNumeral = "("+non0Digit+digit+"?"+digit+"?("+
groupSeparator+digit+digit+digit+")+)";
// digit++ is the possessive form which is necessary for reducing
// backtracking that would otherwise cause unacceptable performance
String numeral = "(("+ digit+"++)|"+groupedNumeral+")";
// JavaScript requires reversal of these two
String numeral = "("
+groupedNumeral
+ "|"
+ "("+ digit+"+)"
+")";
String javaStyleInteger = "([-+]?(" + numeral + "))";
String negativeInteger = negativePrefix + numeral + negativeSuffix;
String positiveInteger = positivePrefix + numeral + positiveSuffix;
return "("+ javaStyleInteger + ")|(" +
positiveInteger + ")|(" +
negativeInteger + ")";
return "("+ javaStyleInteger + ")"
+ "|(" + positiveInteger + ")"
+ "|(" + negativeInteger + ")"
;
}
private Pattern integerPattern() {
if (integerPattern == null) {
Expand Down Expand Up @@ -490,23 +508,31 @@ private static Pattern linePattern() {
private Pattern decimalPattern;
private void buildFloatAndDecimalPattern() {
// \\p{javaDigit} may not be perfect, see above
String digit = "([0-9]|(\\p{javaDigit}))";
String digit = "([0-9])";//|(\\p{javaDigit}))";
String exponent = "([eE][+-]?"+digit+"+)?";
String groupedNumeral = "("+non0Digit+digit+"?"+digit+"?("+
String groupedNumeral = "("+non0Digit+digit+"?"+digit+"?"
+ "("+
groupSeparator+digit+digit+digit+")+)";
// Once again digit++ is used for performance, as above
String numeral = "(("+digit+"++)|"+groupedNumeral+")";
String decimalNumeral = "("+numeral+"|"+numeral +
decimalSeparator + digit + "*+|"+ decimalSeparator +
digit + "++)";
String numeral = "("
+ "("+digit+"+)"
+ "|"+groupedNumeral
+")";
// SwingJS had to move numeral to the end here
String decimalNumeral = "("
+numeral + decimalSeparator + digit + "*"
+ "|"+ decimalSeparator + digit + "+"
+ "|"+numeral
+ ")";
String nonNumber = "(NaN|"+nanString+"|Infinity|"+
infinityString+")";
String positiveFloat = "(" + positivePrefix + decimalNumeral +
positiveSuffix + exponent + ")";
String negativeFloat = "(" + negativePrefix + decimalNumeral +
negativeSuffix + exponent + ")";
String decimal = "(([-+]?" + decimalNumeral + exponent + ")|"+
positiveFloat + "|" + negativeFloat + ")";
String decimal = "(([-+]?" + decimalNumeral + exponent + ")"
+ "|"+ positiveFloat + "|" + negativeFloat
+ ")";
String hexFloat =
"[-+]?0[xX][0-9a-fA-F]*\\.[0-9a-fA-F]+([pP][-+]?[0-9]+)?";
String positiveNonNumber = "(" + positivePrefix + nonNumber +
Expand All @@ -516,8 +542,9 @@ private void buildFloatAndDecimalPattern() {
String signedNonNumber = "(([-+]?"+nonNumber+")|" +
positiveNonNumber + "|" +
negativeNonNumber + ")";
floatPattern = Pattern.compile(decimal + "|" + hexFloat + "|" +
signedNonNumber);
floatPattern = Pattern.compile(decimal
+ "|" + hexFloat + "|" + signedNonNumber
);
decimalPattern = Pattern.compile(decimal);
}
private Pattern floatPattern() {
Expand Down Expand Up @@ -1032,7 +1059,7 @@ private String findPatternInBuffer(Pattern pattern, int horizon) {
return null;
}
// The match could go away depending on what is next
if ((searchLimit == horizonLimit) && matcher.requireEnd()) {
if (matcher.requireEnd()) {
// Rare case: we hit the end of input and it happens
// that it is at the horizon and the end of input is
// required for the match.
Expand Down Expand Up @@ -2275,24 +2302,25 @@ private String processFloatToken(String token) {
if (isNegative)
result = "-" + result;

// Translate non-ASCII digits
Matcher m = NON_ASCII_DIGIT.matcher(result);
if (m.find()) {
StringBuilder inASCII = new StringBuilder();
for (int i=0; i<result.length(); i++) {
char nextChar = result.charAt(i);
if (Character.isDigit(nextChar)) {
int d = Character.digit(nextChar, 10);
if (d != -1)
inASCII.append(d);
else
inASCII.append(nextChar);
} else {
inASCII.append(nextChar);
}
}
result = inASCII.toString();
}
// swingjs NOT IMPLEMENTED
// // Translate non-ASCII digits
// Matcher m = NON_ASCII_DIGIT.matcher(result);
// if (m.find()) {
// StringBuilder inASCII = new StringBuilder();
// for (int i=0; i<result.length(); i++) {
// char nextChar = result.charAt(i);
// if (Character.isDigit(nextChar)) {
// int d = Character.digit(nextChar, 10);
// if (d != -1)
// inASCII.append(d);
// else
// inASCII.append(nextChar);
// } else {
// inASCII.append(nextChar);
// }
// }
// result = inASCII.toString();
// }

return result;
}
Expand Down Expand Up @@ -2629,4 +2657,5 @@ public Scanner reset() {
clearCaches();
return this;
}

}
Loading