From 248d62ff12dade2801f1b8a2d4cb3f75bb944e2e Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sat, 1 Jul 2017 14:08:29 +0300 Subject: [PATCH] Reformat classlib according to checkstyle rules --- classlib/pom.xml | 2 - .../classlib/impl/ServiceLoaderSupport.java | 4 +- .../classlib/impl/tz/ZoneInfoCompiler.java | 3 +- .../org/teavm/classlib/java/lang/TObject.java | 5 + .../java/lang/TStackOverflowError.java | 16 ++ .../lang/reflect/ArrayNativeGenerator.java | 4 +- .../classlib/java/util/TAbstractList.java | 6 +- .../teavm/classlib/java/util/TComparator.java | 2 +- .../teavm/classlib/java/util/TProperties.java | 40 +++- .../org/teavm/classlib/java/util/TRandom.java | 4 +- .../org/teavm/classlib/java/util/TTimer.java | 2 +- .../util/concurrent/TLinkedBlockingDeque.java | 29 ++- .../java/util/function/TBiConsumer.java | 2 +- .../java/util/function/TBiFunction.java | 2 +- .../util/regex/TAbstractLineTerminator.java | 12 +- .../java/util/regex/TAbstractSet.java | 6 +- .../util/regex/TAltGroupQuantifierSet.java | 3 +- .../java/util/regex/TAltQuantifierSet.java | 8 +- .../java/util/regex/TAtomicJointSet.java | 2 +- .../java/util/regex/TBackReferenceSet.java | 15 +- .../util/regex/TBackReferencedSingleSet.java | 2 +- .../java/util/regex/TCIBackReferenceSet.java | 10 +- .../java/util/regex/TCISequenceSet.java | 6 +- .../classlib/java/util/regex/TCharClass.java | 39 ++-- .../classlib/java/util/regex/TCharSet.java | 15 +- .../regex/TCompositeGroupQuantifierSet.java | 5 +- .../util/regex/TCompositeQuantifierSet.java | 9 +- .../java/util/regex/TDecomposedCharSet.java | 24 ++- .../java/util/regex/TDotAllQuantifierSet.java | 16 ++ .../classlib/java/util/regex/TDotAllSet.java | 16 ++ .../java/util/regex/TDotQuantifierSet.java | 16 ++ .../classlib/java/util/regex/TDotSet.java | 16 ++ .../classlib/java/util/regex/TEOISet.java | 19 +- .../classlib/java/util/regex/TEOLSet.java | 33 ++- .../classlib/java/util/regex/TEmptySet.java | 16 ++ .../teavm/classlib/java/util/regex/TFSet.java | 21 +- .../classlib/java/util/regex/TFinalSet.java | 16 ++ .../java/util/regex/TGroupQuantifierSet.java | 20 +- .../util/regex/THangulDecomposedCharSet.java | 66 ++++-- .../util/regex/THighSurrogateCharSet.java | 25 ++- .../classlib/java/util/regex/TIntArrHash.java | 20 +- .../classlib/java/util/regex/TIntHash.java | 20 +- .../classlib/java/util/regex/TJointSet.java | 16 ++ .../java/util/regex/TLeafQuantifierSet.java | 28 ++- .../classlib/java/util/regex/TLeafSet.java | 16 ++ .../classlib/java/util/regex/TLexer.java | 123 ++++++++---- .../util/regex/TLowHighSurrogateRangeSet.java | 18 +- .../java/util/regex/TLowSurrogateCharSet.java | 25 ++- .../java/util/regex/TMatchResult.java | 16 ++ .../java/util/regex/TMatchResultImpl.java | 55 +++-- .../classlib/java/util/regex/TMatcher.java | 56 ++++-- .../java/util/regex/TMultiLineEOLSet.java | 24 ++- .../java/util/regex/TMultiLineSOLSet.java | 22 +- .../java/util/regex/TNegativeLookAhead.java | 19 +- .../java/util/regex/TNegativeLookBehind.java | 16 ++ .../classlib/java/util/regex/TNonCapFSet.java | 16 ++ .../java/util/regex/TNonCapJointSet.java | 16 ++ .../classlib/java/util/regex/TPattern.java | 190 +++++++++++------- .../util/regex/TPatternSyntaxException.java | 16 ++ .../util/regex/TPosAltGroupQuantifierSet.java | 16 ++ .../TPosCompositeGroupQuantifierSet.java | 22 +- .../regex/TPosPlusGroupQuantifierSet.java | 20 +- .../java/util/regex/TPositiveLookAhead.java | 16 ++ .../java/util/regex/TPositiveLookBehind.java | 16 ++ .../regex/TPossessiveAltQuantifierSet.java | 24 ++- .../TPossessiveCompositeQuantifierSet.java | 23 ++- .../regex/TPossessiveGroupQuantifierSet.java | 16 ++ .../util/regex/TPossessiveQuantifierSet.java | 23 ++- .../java/util/regex/TPreviousMatch.java | 16 ++ .../classlib/java/util/regex/TQuantifier.java | 21 +- .../java/util/regex/TQuantifierSet.java | 18 +- .../classlib/java/util/regex/TRangeSet.java | 24 ++- .../util/regex/TRelAltGroupQuantifierSet.java | 25 ++- .../TRelCompositeGroupQuantifierSet.java | 19 +- .../regex/TReluctantAltQuantifierSet.java | 20 +- .../TReluctantCompositeQuantifierSet.java | 16 ++ .../regex/TReluctantGroupQuantifierSet.java | 19 +- .../util/regex/TReluctantQuantifierSet.java | 16 ++ .../classlib/java/util/regex/TSOLSet.java | 16 ++ .../java/util/regex/TSequenceSet.java | 52 +++-- .../classlib/java/util/regex/TSingleSet.java | 22 +- .../java/util/regex/TSpecialToken.java | 16 ++ .../java/util/regex/TSupplCharSet.java | 31 ++- .../java/util/regex/TSupplRangeSet.java | 33 ++- .../java/util/regex/TUCIBackReferenceSet.java | 19 +- .../classlib/java/util/regex/TUCICharSet.java | 16 ++ .../util/regex/TUCIDecomposedCharSet.java | 18 +- .../java/util/regex/TUCIRangeSet.java | 18 +- .../java/util/regex/TUCISequenceSet.java | 18 +- .../java/util/regex/TUCISupplCharSet.java | 16 ++ .../java/util/regex/TUCISupplRangeSet.java | 16 ++ .../classlib/java/util/regex/TUEOLSet.java | 19 +- .../java/util/regex/TUMultiLineEOLSet.java | 24 ++- .../java/util/regex/TUnicodeCategory.java | 16 ++ .../util/regex/TUnicodeCategoryScope.java | 16 ++ .../util/regex/TUnifiedQuantifierSet.java | 26 ++- .../java/util/regex/TWordBoundary.java | 25 ++- 97 files changed, 1674 insertions(+), 382 deletions(-) diff --git a/classlib/pom.xml b/classlib/pom.xml index a1a0cafa9..4633052fa 100644 --- a/classlib/pom.xml +++ b/classlib/pom.xml @@ -87,7 +87,6 @@ - org.apache.felix maven-bundle-plugin diff --git a/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java b/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java index b9dea1409..5bcf2d7d9 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java @@ -28,12 +28,12 @@ import java.util.List; import java.util.Map; import java.util.Set; import org.teavm.backend.javascript.codegen.SourceWriter; +import org.teavm.backend.javascript.spi.Generator; +import org.teavm.backend.javascript.spi.GeneratorContext; import org.teavm.dependency.AbstractDependencyListener; import org.teavm.dependency.DependencyAgent; import org.teavm.dependency.DependencyNode; import org.teavm.dependency.MethodDependency; -import org.teavm.backend.javascript.spi.Generator; -import org.teavm.backend.javascript.spi.GeneratorContext; import org.teavm.model.CallLocation; import org.teavm.model.MethodDescriptor; import org.teavm.model.MethodReference; diff --git a/classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java b/classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java index f5a1276c8..d79457c5f 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java @@ -414,8 +414,7 @@ public class ZoneInfoCompiler { /** * Adds a recurring savings rule to the builder. */ - public void addRecurring(DateTimeZoneBuilder builder, int saveMillis, int fromYear, int toYear) - { + public void addRecurring(DateTimeZoneBuilder builder, int saveMillis, int fromYear, int toYear) { builder.addRecurringSavings(saveMillis, fromYear, toYear, iZoneChar, diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java index 306b40ddf..8ac28cdeb 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java @@ -185,6 +185,11 @@ public class TObject { return identity(); } + @Override + public boolean equals(Object obj) { + return equals0((TObject) obj); + } + @Rename("equals") public boolean equals0(TObject other) { return this == other; diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TStackOverflowError.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TStackOverflowError.java index 65c108b2e..0b95e23bb 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TStackOverflowError.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TStackOverflowError.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Copyright 2016 Sergey Kapralov. * diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java b/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java index 198222228..e76415b2b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/reflect/ArrayNativeGenerator.java @@ -17,9 +17,11 @@ package org.teavm.classlib.java.lang.reflect; import java.io.IOException; import org.teavm.backend.javascript.codegen.SourceWriter; -import org.teavm.dependency.*; import org.teavm.backend.javascript.spi.Generator; import org.teavm.backend.javascript.spi.GeneratorContext; +import org.teavm.dependency.DependencyAgent; +import org.teavm.dependency.DependencyPlugin; +import org.teavm.dependency.MethodDependency; import org.teavm.model.CallLocation; import org.teavm.model.ClassReader; import org.teavm.model.MethodDescriptor; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java b/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java index 179f60306..7328708ba 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java @@ -160,7 +160,6 @@ public abstract class TAbstractList extends TAbstractCollection implements } } - @Override public int hashCode() { int hashCode = 1; @@ -171,6 +170,11 @@ public abstract class TAbstractList extends TAbstractCollection implements return hashCode; } + @Override + public boolean equals(Object obj) { + return equals0((TObject) obj); + } + @Override @Rename("equals") public boolean equals0(TObject other) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java b/classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java index dac75c6a7..f89a14a5f 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java @@ -50,7 +50,7 @@ public interface TComparator { } default > TComparator thenComparing( - TFunction keyExtractor) { + TFunction keyExtractor) { return (a, b) -> { int r = compare(a, b); if (r == 0) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java b/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java index f7eda921b..c80950b57 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java @@ -31,7 +31,12 @@ public class TProperties extends THashtable { */ protected TProperties defaults; - private static final int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, KEY_DONE = 4, IGNORE = 5; + private static final int NONE = 0; + private static final int SLASH = 1; + private static final int UNICODE = 2; + private static final int CONTINUE = 3; + private static final int KEY_DONE = 4; + private static final int IGNORE = 5; public TProperties() { super(); @@ -42,7 +47,8 @@ public class TProperties extends THashtable { } private void dumpString(StringBuilder buffer, String string, boolean isKey) { - int index = 0, length = string.length(); + int index = 0; + int length = string.length(); if (!isKey && index < length && string.charAt(index) == ' ') { buffer.append("\\ "); //$NON-NLS-1$ index++; @@ -78,7 +84,9 @@ public class TProperties extends THashtable { private char[] toHexaDecimal(final int ch) { char[] hexChars = { '\\', 'u', '0', '0', '0', '0' }; - int hexChar, index = hexChars.length, copyOfCh = ch; + int hexChar; + int index = hexChars.length; + int copyOfCh = ch; do { hexChar = copyOfCh & 15; if (hexChar > 9) { @@ -87,7 +95,8 @@ public class TProperties extends THashtable { hexChar += '0'; } hexChars[--index] = (char) hexChar; - } while ((copyOfCh >>>= 4) != 0); + copyOfCh >>>= 4; + } while (copyOfCh != 0); return hexChars; } @@ -144,9 +153,14 @@ public class TProperties extends THashtable { if (in == null) { throw new NullPointerException(); } - int mode = NONE, unicode = 0, count = 0; - char nextChar, buf[] = new char[40]; - int offset = 0, keyLength = -1, intVal; + int mode = NONE; + int unicode = 0; + int count = 0; + char nextChar; + char[] buf = new char[40]; + int offset = 0; + int keyLength = -1; + int intVal; boolean firstChar = true; TBufferedInputStream bis = new TBufferedInputStream(in); @@ -214,7 +228,8 @@ public class TProperties extends THashtable { break; case 'u': mode = UNICODE; - unicode = count = 0; + unicode = 0; + count = 0; continue; } } else { @@ -242,7 +257,13 @@ public class TProperties extends THashtable { continue; } // fall into the next case + break; case '\r': + if (mode == CONTINUE) { // Part of a \r\n sequence + mode = IGNORE; // Ignore whitespace on the next line + continue; + } + mode = NONE; firstChar = true; if (offset > 0 || (offset == 0 && keyLength == 0)) { @@ -311,7 +332,7 @@ public class TProperties extends THashtable { } private void selectProperties(THashtable selected) { - if(defaults != null) { + if (defaults != null) { defaults.selectProperties(selected); } selected.putAll(this); @@ -322,6 +343,7 @@ public class TProperties extends THashtable { try { store(out, comment); } catch (TIOException e) { + // do nothing } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java b/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java index 723687ad5..efcc92736 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java @@ -89,7 +89,9 @@ public class TRandom extends TObject implements TSerializable { return storedGaussian; } - double v1, v2, s; + double v1; + double v2; + double s; do { v1 = 2 * nextDouble() - 1; v2 = 2 * nextDouble() - 1; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java b/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java index c262afe70..bb066f7a6 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java @@ -91,7 +91,7 @@ public class TTimer extends TObject { return; } long nextDelay = nextStartTime[0] - System.currentTimeMillis(); - if (nextDelay < 0 ) { + if (nextDelay < 0) { nextDelay = 0; } task.nativeTimerId = Window.setTimeout(this, (int) nextDelay); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TLinkedBlockingDeque.java b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TLinkedBlockingDeque.java index 8f1383c1c..1aad54e9c 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TLinkedBlockingDeque.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TLinkedBlockingDeque.java @@ -1,16 +1,29 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.teavm.classlib.java.util.concurrent; import org.teavm.classlib.java.util.TCollection; import org.teavm.classlib.java.util.TLinkedList; public class TLinkedBlockingDeque extends TLinkedList { + public TLinkedBlockingDeque() { + super(); + } - public TLinkedBlockingDeque() { - super(); - } - - public TLinkedBlockingDeque(TCollection coll) { - super(coll); - } - + public TLinkedBlockingDeque(TCollection coll) { + super(coll); + } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java b/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java index e5c9f289d..7b06e9104 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java @@ -19,7 +19,7 @@ package org.teavm.classlib.java.util.function; public interface TBiConsumer { void accept(T t, U u); - default TBiConsumer andThen(TBiConsumer after) { + default TBiConsumer andThen(TBiConsumer after) { return (t, u) -> { this.accept(t, u); after.accept(t, u); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java b/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java index cc9a3804b..79d871a3b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java @@ -19,7 +19,7 @@ package org.teavm.classlib.java.util.function; public interface TBiFunction { R apply(T t, U u); - default TBiFunction andThen(TFunction after) { + default TBiFunction andThen(TFunction after) { return (t, u) -> after.apply(apply(t, u)); } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractLineTerminator.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractLineTerminator.java index 377402d03..bd44c837f 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractLineTerminator.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractLineTerminator.java @@ -41,9 +41,9 @@ package org.teavm.classlib.java.util.regex; * @author Nikolay A. Kuznetsov */ abstract class TAbstractLineTerminator { - static TAbstractLineTerminator unixLT = null; + static TAbstractLineTerminator unixLT; - static TAbstractLineTerminator unicodeLT = null; + static TAbstractLineTerminator unicodeLT; public abstract boolean isLineTerminator(int ch); @@ -51,8 +51,9 @@ abstract class TAbstractLineTerminator { public static TAbstractLineTerminator getInstance(int flag) { if ((flag & TPattern.UNIX_LINES) != 0) { - if (unixLT != null) + if (unixLT != null) { return unixLT; + } unixLT = new TAbstractLineTerminator() { @Override public boolean isLineTerminator(int ch) { @@ -66,12 +67,13 @@ abstract class TAbstractLineTerminator { }; return unixLT; } else { - if (unicodeLT != null) + if (unicodeLT != null) { return unicodeLT; + } unicodeLT = new TAbstractLineTerminator() { @Override public boolean isLineTerminator(int ch) { - return (ch == '\n' || ch == '\r' || ch == '\u0085' || (ch | 1) == '\u2029'); + return ch == '\n' || ch == '\r' || ch == '\u0085' || (ch | 1) == '\u2029'; } @Override diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractSet.java index d985b2a11..31989d357 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractSet.java @@ -61,11 +61,11 @@ abstract class TAbstractSet { */ static int counter = 1; - protected boolean isSecondPassVisited = false; + protected boolean isSecondPassVisited; protected String index = new Integer(TAbstractSet.counter++).toString(); - private int type = 0; + private int type; public TAbstractSet() { } @@ -239,7 +239,7 @@ abstract class TAbstractSet { /* * Add here code to do during the pass */ - if (next instanceof TSingleSet && ((TFSet)((TJointSet)next).fSet).isBackReferenced) { + if (next instanceof TSingleSet && ((TFSet) ((TJointSet) next).fSet).isBackReferenced) { next = next.next; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltGroupQuantifierSet.java index 37a56020f..ea1e62494 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltGroupQuantifierSet.java @@ -47,8 +47,9 @@ class TAltGroupQuantifierSet extends TGroupQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - if (!innerSet.hasConsumed(matchResult)) + if (!innerSet.hasConsumed(matchResult)) { return next.matches(stringIndex, testString, matchResult); + } int nextIndex = innerSet.matches(stringIndex, testString, matchResult); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltQuantifierSet.java index 7dae4eb19..84cf332cb 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAltQuantifierSet.java @@ -48,13 +48,9 @@ class TAltQuantifierSet extends TLeafQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - int shift = 0; + int shift = innerSet.matches(stringIndex, testString, matchResult); - if ((shift = innerSet.matches(stringIndex, testString, matchResult)) >= 0) { - return shift; - } else { - return next.matches(stringIndex, testString, matchResult); - } + return shift >= 0 ? shift : next.matches(stringIndex, testString, matchResult); } @Override diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAtomicJointSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAtomicJointSet.java index 1a83280d0..1be218d99 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAtomicJointSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TAtomicJointSet.java @@ -63,7 +63,7 @@ class TAtomicJointSet extends TNonCapJointSet { if (shift >= 0) { // AtomicFset always returns true, but saves the index to run // this next.match() from; - return next.matches(((TAtomicFSet)fSet).getIndex(), testString, matchResult); + return next.matches(((TAtomicFSet) fSet).getIndex(), testString, matchResult); } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferenceSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferenceSet.java index 937b2672f..d5fd4f440 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferenceSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferenceSet.java @@ -49,8 +49,9 @@ class TBackReferenceSet extends TCIBackReferenceSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { String group = getString(matchResult); - if (group == null || (stringIndex + group.length()) > matchResult.getRightBound()) + if (group == null || (stringIndex + group.length()) > matchResult.getRightBound()) { return -1; + } int shift = testString.toString().startsWith(group, stringIndex) ? group.length() : -1; if (shift < 0) { @@ -65,16 +66,18 @@ class TBackReferenceSet extends TCIBackReferenceSet { String group = getString(matchResult); int strLength = matchResult.getLeftBound(); - if (group == null || (strIndex + group.length()) > strLength) + if (group == null || (strIndex + group.length()) > strLength) { return -1; + } String testStr = testString.toString(); while (strIndex <= strLength) { strIndex = testStr.indexOf(group, strIndex); - if (strIndex < 0) + if (strIndex < 0) { return -1; + } if (next.matches(strIndex + group.length(), testString, matchResult) >= 0) { return strIndex; } @@ -89,16 +92,18 @@ class TBackReferenceSet extends TCIBackReferenceSet { public int findBack(int strIndex, int lastIndex, CharSequence testString, TMatchResultImpl matchResult) { String group = getString(matchResult); - if (group == null) + if (group == null) { return -1; + } String testStr = testString.toString(); while (lastIndex >= strIndex) { lastIndex = testStr.lastIndexOf(group, lastIndex); - if (lastIndex < 0 || lastIndex < strIndex) + if (lastIndex < 0 || lastIndex < strIndex) { return -1; + } if (next.matches(lastIndex + group.length(), testString, matchResult) >= 0) { return lastIndex; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferencedSingleSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferencedSingleSet.java index 7296d8c02..7f15e4a47 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferencedSingleSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TBackReferencedSingleSet.java @@ -62,7 +62,7 @@ class TBackReferencedSingleSet extends TSingleSet { } public TBackReferencedSingleSet(TSingleSet node) { - super(node.kid, ((TFSet)node.fSet)); + super(node.kid, (TFSet) node.fSet); } @Override diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCIBackReferenceSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCIBackReferenceSet.java index bfd34251c..37f7c3ced 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCIBackReferenceSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCIBackReferenceSet.java @@ -57,12 +57,13 @@ class TCIBackReferenceSet extends TJointSet { public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { String group = getString(matchResult); - if (group == null || (stringIndex + group.length()) > matchResult.getRightBound()) + if (group == null || (stringIndex + group.length()) > matchResult.getRightBound()) { return -1; + } for (int i = 0; i < group.length(); i++) { - if (group.charAt(i) != testString.charAt(stringIndex + i) && - TPattern.getSupplement(group.charAt(i)) != testString.charAt(stringIndex + i)) { + if (group.charAt(i) != testString.charAt(stringIndex + i) + && TPattern.getSupplement(group.charAt(i)) != testString.charAt(stringIndex + i)) { return -1; } } @@ -92,8 +93,7 @@ class TCIBackReferenceSet extends TJointSet { @Override public boolean hasConsumed(TMatchResultImpl matchResult) { - int cons; - boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0); + boolean res = matchResult.getConsumed(consCounter) != 0; matchResult.setConsumed(consCounter, -1); return res; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCISequenceSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCISequenceSet.java index 3aeb9d8de..ab3f9f247 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCISequenceSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCISequenceSet.java @@ -41,7 +41,7 @@ package org.teavm.classlib.java.util.regex; * @author Nikolay A. Kuznetsov */ class TCISequenceSet extends TLeafSet { - private String string = null; + private String string; TCISequenceSet(StringBuffer substring) { this.string = substring.toString(); @@ -51,8 +51,8 @@ class TCISequenceSet extends TLeafSet { @Override public int accepts(int strIndex, CharSequence testString) { for (int i = 0; i < string.length(); i++) { - if (string.charAt(i) != testString.charAt(strIndex + i) && - TPattern.getSupplement(string.charAt(i)) != testString.charAt(strIndex + i)) { + if (string.charAt(i) != testString.charAt(strIndex + i) + && TPattern.getSupplement(string.charAt(i)) != testString.charAt(strIndex + i)) { return -1; } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharClass.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharClass.java index 771dddb48..d5b9c5d9d 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharClass.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharClass.java @@ -45,22 +45,22 @@ import java.util.BitSet; */ class TCharClass extends TAbstractCharClass { // Flag indicates if we add supplement upper/lower case - boolean ci = false; + boolean ci; - boolean uci = false; + boolean uci; // Flag indicates if there are unicode supplements - boolean hasUCI = false; + boolean hasUCI; - boolean invertedSurrogates = false; + boolean invertedSurrogates; - boolean inverted = false; + boolean inverted; - boolean hideBits = false; + boolean hideBits; BitSet bits = new BitSet(); - TAbstractCharClass nonBitSet = null; + TAbstractCharClass nonBitSet; public TCharClass() { } @@ -83,9 +83,9 @@ class TCharClass extends TAbstractCharClass { if (ci) { if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { if (!inverted) { - bits.set(TPattern.getSupplement((char)ch)); + bits.set(TPattern.getSupplement((char) ch)); } else { - bits.clear(TPattern.getSupplement((char)ch)); + bits.clear(TPattern.getSupplement((char) ch)); } } else if (uci && ch > 128) { hasUCI = true; @@ -104,8 +104,9 @@ class TCharClass extends TAbstractCharClass { if (!inverted) { bits.set(ch); - } else + } else { bits.clear(ch); + } if (!mayContainSupplCodepoints && Character.isSupplementaryCodePoint(ch)) { mayContainSupplCodepoints = true; @@ -242,8 +243,9 @@ class TCharClass extends TAbstractCharClass { } public TCharClass add(int st, int end) { - if (st > end) + if (st > end) { throw new IllegalArgumentException(); + } if (!ci // no intersection with surrogate characters @@ -268,8 +270,9 @@ class TCharClass extends TAbstractCharClass { mayContainSupplCodepoints = true; } - if (clazz.hasUCI()) + if (clazz.hasUCI()) { this.hasUCI = true; + } if (altSurrogates ^ clazz.altSurrogates) { @@ -395,8 +398,9 @@ class TCharClass extends TAbstractCharClass { mayContainSupplCodepoints = true; } - if (clazz.hasUCI()) + if (clazz.hasUCI()) { this.hasUCI = true; + } if (altSurrogates ^ clazz.altSurrogates) { @@ -538,8 +542,9 @@ class TCharClass extends TAbstractCharClass { @Override protected BitSet getBits() { - if (hideBits) + if (hideBits) { return null; + } return bits; } @@ -568,8 +573,9 @@ class TCharClass extends TAbstractCharClass { temp.append('|'); } - if (temp.length() > 0) + if (temp.length() > 0) { temp.deleteCharAt(temp.length() - 1); + } return temp.toString(); } @@ -590,8 +596,9 @@ class TCharClass extends TAbstractCharClass { temp.append('|'); } - if (temp.length() > 0) + if (temp.length() > 0) { temp.deleteCharAt(temp.length() - 1); + } return temp.toString(); } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharSet.java index 7ab24de04..0b6f0f421 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCharSet.java @@ -42,7 +42,7 @@ package org.teavm.classlib.java.util.regex; */ class TCharSet extends TLeafSet { - private char ch = 0; + private char ch; public TCharSet(char ch) { this.ch = ch; @@ -61,13 +61,14 @@ class TCharSet extends TLeafSet { @Override public int find(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { - String testStr = (String)testString; + String testStr = (String) testString; int strLength = matchResult.getRightBound(); while (strIndex < strLength) { strIndex = testStr.indexOf(ch, strIndex); - if (strIndex < 0) + if (strIndex < 0) { return -1; + } if (next.matches(strIndex + 1, testString, matchResult) >= 0) { return strIndex; } @@ -83,7 +84,7 @@ class TCharSet extends TLeafSet { @Override public int findBack(int strIndex, int lastIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { - String testStr = (String)testString; + String testStr = (String) testString; while (lastIndex >= strIndex) { lastIndex = testStr.lastIndexOf(ch, lastIndex); @@ -116,11 +117,11 @@ class TCharSet extends TLeafSet { @Override public boolean first(TAbstractSet set) { if (set instanceof TCharSet) { - return ((TCharSet)set).getChar() == ch; + return ((TCharSet) set).getChar() == ch; } else if (set instanceof TRangeSet) { - return ((TRangeSet)set).accepts(0, Character.toString(ch)) > 0; + return ((TRangeSet) set).accepts(0, Character.toString(ch)) > 0; } else if (set instanceof TSupplRangeSet) { - return ((TSupplRangeSet)set).contains(ch); + return ((TSupplRangeSet) set).contains(ch); } else if (set instanceof TSupplCharSet) { return false; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeGroupQuantifierSet.java index 451c01aac..3f1885994 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeGroupQuantifierSet.java @@ -42,7 +42,7 @@ package org.teavm.classlib.java.util.regex; */ class TCompositeGroupQuantifierSet extends TGroupQuantifierSet { - protected TQuantifier quantifier = null; + protected TQuantifier quantifier; int setCounter; @@ -57,8 +57,9 @@ class TCompositeGroupQuantifierSet extends TGroupQuantifierSet { public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int enterCounter = matchResult.getEnterCounter(setCounter); - if (!innerSet.hasConsumed(matchResult)) + if (!innerSet.hasConsumed(matchResult)) { return next.matches(stringIndex, testString, matchResult); + } // can't go inner set; if (enterCounter >= quantifier.max()) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeQuantifierSet.java index 3b83d7ae1..86e2983d3 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TCompositeQuantifierSet.java @@ -42,7 +42,7 @@ package org.teavm.classlib.java.util.regex; */ class TCompositeQuantifierSet extends TLeafQuantifierSet { - protected TQuantifier quantifier = null; + protected TQuantifier quantifier; public TCompositeQuantifierSet(TQuantifier quant, TLeafSet innerSet, TAbstractSet next, int type) { super(innerSet, next, type); @@ -71,8 +71,11 @@ class TCompositeQuantifierSet extends TLeafQuantifierSet { for (; i < max; i++) { int shift; - if (stringIndex + leaf.charCount() > matchResult.getRightBound() || - (shift = leaf.accepts(stringIndex, testString)) < 1) { + if (stringIndex + leaf.charCount() > matchResult.getRightBound()) { + break; + } + shift = leaf.accepts(stringIndex, testString); + if (shift < 1) { break; } stringIndex += shift; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java index 9405485dd..ebae75837 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,7 +48,7 @@ class TDecomposedCharSet extends TJointSet { /** * UTF-16 encoding of decomposedChar */ - private String decomposedCharUTF16 = null; + private String decomposedCharUTF16; /** * Decomposition of the Unicode codepoint @@ -109,7 +125,7 @@ class TDecomposedCharSet extends TJointSet { * Read testString until we met a decomposed char boundary and * decompose obtained portion of testString */ - while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH)) { + while (readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH) { if (TLexer.hasDecompositionNonNullCanClass(curChar)) { @@ -214,8 +230,8 @@ class TDecomposedCharSet extends TJointSet { @Override public boolean first(TAbstractSet set) { - return (set instanceof TDecomposedCharSet) ? ((TDecomposedCharSet)set).getDecomposedChar().equals( - getDecomposedChar()) : true; + return !(set instanceof TDecomposedCharSet) + || ((TDecomposedCharSet) set).getDecomposedChar().equals(getDecomposedChar()); } @Override diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllQuantifierSet.java index a2c1e9889..f3a8bf24a 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllSet.java index 498405205..8fbb5c88d 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotAllSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java index ed9d43bc6..c36166314 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotSet.java index 2939181fd..ddaae5bc7 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOISet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOISet.java index fcd8b4e00..82b343c6f 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOISet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOISet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -30,8 +46,9 @@ class TEOISet extends TAbstractSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int rightBound = matchResult.hasTransparentBounds() ? testString.length() : matchResult.getRightBound(); - if (stringIndex < rightBound) + if (stringIndex < rightBound) { return -1; + } matchResult.hitEnd = true; matchResult.requireEnd = true; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOLSet.java index c264c039a..490575ddb 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEOLSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -42,17 +58,19 @@ final class TEOLSet extends TAbstractSet { } // check final line terminator; - if ((rightBound - strIndex) == 2 && testString.charAt(strIndex) == '\r' && - testString.charAt(strIndex + 1) == '\n') { + if ((rightBound - strIndex) == 2 && testString.charAt(strIndex) == '\r' + && testString.charAt(strIndex + 1) == '\n') { matchResult.setConsumed(consCounter, 0); return next.matches(strIndex, testString, matchResult); } char ch; - if ((rightBound - strIndex) == 1 && - (((ch = testString.charAt(strIndex)) == '\n' || ch == '\r' || ch == '\u0085' || (ch | 1) == '\u2029'))) { - matchResult.setConsumed(consCounter, 0); - return next.matches(strIndex, testString, matchResult); + if ((rightBound - strIndex) == 1) { + ch = testString.charAt(strIndex); + if (ch == '\n' || ch == '\r' || ch == '\u0085' || (ch | 1) == '\u2029') { + matchResult.setConsumed(consCounter, 0); + return next.matches(strIndex, testString, matchResult); + } } return -1; @@ -60,8 +78,7 @@ final class TEOLSet extends TAbstractSet { @Override public boolean hasConsumed(TMatchResultImpl matchResult) { - int cons; - boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0); + boolean res = matchResult.getConsumed(consCounter) != 0; matchResult.setConsumed(consCounter, -1); return res; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEmptySet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEmptySet.java index 2467a7570..6ffa9e790 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEmptySet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TEmptySet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFSet.java index 9b2ca8cc7..e2fa3c4ac 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -29,7 +45,7 @@ class TFSet extends TAbstractSet { static PossessiveFSet posFSet = new PossessiveFSet(); - boolean isBackReferenced = false; + boolean isBackReferenced; private int groupIndex; @@ -46,8 +62,9 @@ class TFSet extends TAbstractSet { * if(shift >=0 && matchResult.getEnd(groupIndex) == -1) { * matchResult.setEnd(groupIndex, stringIndex); } */ - if (shift < 0) + if (shift < 0) { matchResult.setEnd(groupIndex, end); + } return shift; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFinalSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFinalSet.java index 8325d53c1..3f5739c8f 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFinalSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TFinalSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TGroupQuantifierSet.java index ca0c23037..81bcce2e0 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,8 +51,10 @@ class TGroupQuantifierSet extends TQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - if (!innerSet.hasConsumed(matchResult)) + if (!innerSet.hasConsumed(matchResult)) { return next.matches(stringIndex, testString, matchResult); + } + int nextIndex = innerSet.matches(stringIndex, testString, matchResult); if (nextIndex < 0) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/THangulDecomposedCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/THangulDecomposedCharSet.java index 44e121900..5af406a78 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/THangulDecomposedCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/THangulDecomposedCharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -31,7 +47,7 @@ class THangulDecomposedCharSet extends TJointSet { /** * String representing syllable */ - private String decomposedCharUTF16 = null; + private String decomposedCharUTF16; /** * Length of useful part of decomposedChar decomposedCharLength <= @@ -69,7 +85,10 @@ class THangulDecomposedCharSet extends TJointSet { * @return - string representation. */ private String getDecomposedChar() { - return (decomposedCharUTF16 == null) ? (decomposedCharUTF16 = new String(decomposedChar)) : decomposedCharUTF16; + if (decomposedCharUTF16 == null) { + decomposedCharUTF16 = new String(decomposedChar); + } + return decomposedCharUTF16; } @Override @@ -85,7 +104,7 @@ class THangulDecomposedCharSet extends TJointSet { * equal Lexer.MAX_DECOMPOSITION_LENGTH */ int rightBound = matchResult.getRightBound(); - int SyllIndex = 0; + int syllIndex = 0; int[] decompSyllable = new int[TLexer.MAX_HANGUL_DECOMPOSITION_LENGTH]; int[] decompCurSymb; char curSymb; @@ -95,9 +114,9 @@ class THangulDecomposedCharSet extends TJointSet { * http://www.unicode.org/versions/Unicode4.0.0/ch03.pdf * "3.12 Conjoining Jamo Behavior" */ - int LIndex = -1; - int VIndex = -1; - int TIndex = -1; + int lIndex; + int vIndex = -1; + int tIndex = -1; if (strIndex >= rightBound) { return -1; @@ -111,10 +130,10 @@ class THangulDecomposedCharSet extends TJointSet { * We deal with ordinary letter or sequence of jamos at strIndex at * testString. */ - decompSyllable[SyllIndex++] = curSymb; - LIndex = curSymb - TLexer.LBase; + decompSyllable[syllIndex++] = curSymb; + lIndex = curSymb - TLexer.LBase; - if ((LIndex < 0) || (LIndex >= TLexer.LCount)) { + if ((lIndex < 0) || (lIndex >= TLexer.LCount)) { /* * Ordinary letter, that doesn't match this @@ -124,10 +143,10 @@ class THangulDecomposedCharSet extends TJointSet { if (strIndex < rightBound) { curSymb = testString.charAt(strIndex); - VIndex = curSymb - TLexer.VBase; + vIndex = curSymb - TLexer.VBase; } - if ((VIndex < 0) || (VIndex >= TLexer.VCount)) { + if ((vIndex < 0) || (vIndex >= TLexer.VCount)) { /* * Single L jamo doesn't compose Hangul syllable, so doesn't @@ -136,30 +155,33 @@ class THangulDecomposedCharSet extends TJointSet { return -1; } strIndex++; - decompSyllable[SyllIndex++] = curSymb; + decompSyllable[syllIndex++] = curSymb; if (strIndex < rightBound) { curSymb = testString.charAt(strIndex); - TIndex = curSymb - TLexer.TBase; + tIndex = curSymb - TLexer.TBase; } - if ((TIndex < 0) || (TIndex >= TLexer.TCount)) { + if ((tIndex < 0) || (tIndex >= TLexer.TCount)) { /* * We deal with LV syllable at testString, so compare it to this */ - return ((decomposedCharLength == 2) && (decompSyllable[0] == decomposedChar[0]) && (decompSyllable[1] == decomposedChar[1])) ? next - .matches(strIndex, testString, matchResult) : -1; + return decomposedCharLength == 2 && decompSyllable[0] == decomposedChar[0] + && decompSyllable[1] == decomposedChar[1] + ? next.matches(strIndex, testString, matchResult) + : -1; } strIndex++; - decompSyllable[SyllIndex++] = curSymb; + decompSyllable[syllIndex++] = curSymb; /* * We deal with LVT syllable at testString, so compare it to this */ - return ((decomposedCharLength == 3) && (decompSyllable[0] == decomposedChar[0]) && - (decompSyllable[1] == decomposedChar[1]) && (decompSyllable[2] == decomposedChar[2])) ? next - .matches(strIndex, testString, matchResult) : -1; + return decomposedCharLength == 3 && decompSyllable[0] == decomposedChar[0] + && decompSyllable[1] == decomposedChar[1] && decompSyllable[2] == decomposedChar[2] + ? next.matches(strIndex, testString, matchResult) + : -1; } else { /* @@ -183,8 +205,8 @@ class THangulDecomposedCharSet extends TJointSet { @Override public boolean first(TAbstractSet set) { - return (set instanceof THangulDecomposedCharSet) ? ((THangulDecomposedCharSet)set).getDecomposedChar().equals( - getDecomposedChar()) : true; + return !(set instanceof THangulDecomposedCharSet) + || ((THangulDecomposedCharSet) set).getDecomposedChar().equals(getDecomposedChar()); } @Override diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/THighSurrogateCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/THighSurrogateCharSet.java index c25bca1a6..6efbe5096 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/THighSurrogateCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/THighSurrogateCharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -151,14 +167,15 @@ class THighSurrogateCharSet extends TJointSet { @Override public int find(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { - String testStr = (String)testString; + String testStr = (String) testString; int strLength = matchResult.getRightBound(); while (strIndex < strLength) { strIndex = testStr.indexOf(high, strIndex); - if (strIndex < 0) + if (strIndex < 0) { return -1; + } if (strIndex + 1 < strLength) { @@ -187,7 +204,7 @@ class THighSurrogateCharSet extends TJointSet { @Override public int findBack(int strIndex, int lastIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { - String testStr = (String)testString; + String testStr = (String) testString; int strLength = matchResult.getRightBound(); while (lastIndex >= strIndex) { @@ -243,7 +260,7 @@ class THighSurrogateCharSet extends TJointSet { } else if (set instanceof TLowSurrogateCharSet) { return false; } else if (set instanceof THighSurrogateCharSet) { - return ((THighSurrogateCharSet)set).high == this.high; + return ((THighSurrogateCharSet) set).high == this.high; } return true; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntArrHash.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntArrHash.java index e6a6b178d..adde16e44 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntArrHash.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntArrHash.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -41,7 +57,7 @@ class TIntArrHash { int i = 0; int hashCode = key & mask; - for (; ; ) { + while (true) { if (table[hashCode] == 0 // empty || table[hashCode] == key) { // rewrite table[hashCode] = key; @@ -61,7 +77,7 @@ class TIntArrHash { int i = 0; int storedKey; - for (; ; ) { + while (true) { storedKey = table[hashCode]; if (storedKey == 0) { // empty diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntHash.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntHash.java index 325c291fc..80afce18b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntHash.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TIntHash.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -43,7 +59,7 @@ class TIntHash { int i = 0; int hashCode = key & mask; - for (; ; ) { + while (true) { if (table[hashCode] == 0 // empty || table[hashCode] == key) { // rewrite table[hashCode] = key; @@ -63,7 +79,7 @@ class TIntHash { int i = 0; int storedKey; - for (; ; ) { + while (true) { storedKey = table[hashCode]; if (storedKey == 0) { // empty diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TJointSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TJointSet.java index 281d87bf8..387f89c1f 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TJointSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TJointSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafQuantifierSet.java index 6b96c6197..ddaf66adb 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -37,8 +53,11 @@ class TLeafQuantifierSet extends TQuantifierSet { int i = 0; int shift = 0; - while (stringIndex + leaf.charCount() <= matchResult.getRightBound() && - (shift = leaf.accepts(stringIndex, testString)) > 0) { + while (stringIndex + leaf.charCount() <= matchResult.getRightBound()) { + shift = leaf.accepts(stringIndex, testString); + if (shift <= 0) { + break; + } stringIndex += shift; i++; } @@ -67,9 +86,10 @@ class TLeafQuantifierSet extends TQuantifierSet { */ @Override public void setInnerSet(TAbstractSet innerSet) { - if (!(innerSet instanceof TLeafSet)) + if (!(innerSet instanceof TLeafSet)) { throw new RuntimeException(""); + } super.setInnerSet(innerSet); - this.leaf = (TLeafSet)innerSet; + this.leaf = (TLeafSet) innerSet; } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafSet.java index e7c914ce6..2a651c687 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLeafSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java index a27a02abc..624fddfc5 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -145,23 +161,23 @@ class TLexer { static final int NCount = 588; // table that contains canonical decomposition mappings - private static TIntArrHash decompTable = null; + private static TIntArrHash decompTable; /* * Table that contains information about Unicode codepoints with single * codepoint decomposition */ - private static TIntHash singleDecompTable = null; + private static TIntHash singleDecompTable; private static int singleDecompTableSize; - private char[] pattern = null; + private char[] pattern; - private int flags = 0; + private int flags; private int mode = 1; // when in literal mode, this field will save the previous one - private int saved_mode = 0; + private int savedMode; // previous char read private int lookBack; @@ -173,28 +189,28 @@ class TLexer { private int lookAhead; // index of last char in pattern plus one - private int patternFullLength = 0; + private int patternFullLength; // cur special token - private TSpecialToken curST = null; + private TSpecialToken curST; // next special token - private TSpecialToken lookAheadST = null; + private TSpecialToken lookAheadST; // cur char being processed - private int index = 0; + private int index; // previous non-whitespace character index; - private int prevNW = 0; + private int prevNW; // cur token start index - private int curToc = 0; + private int curToc; // look ahead token index - private int lookAheadToc = 0; + private int lookAheadToc; // original string representing pattern - private String orig = null; + private String orig; public TLexer(String pattern, int flags) { orig = pattern; @@ -353,7 +369,7 @@ class TLexer { switch (lookAhead) { case 'E': { - mode = saved_mode; + mode = savedMode; lookAhead = (index <= pattern.length - 2) ? nextCodePoint() : 0; break; @@ -381,8 +397,9 @@ class TLexer { String cs = parseCharClassName(); boolean negative = false; - if (lookAhead == 'P') + if (lookAhead == 'P') { negative = true; + } try { lookAheadST = TAbstractCharClass.getPredefinedClass(cs, negative); } catch (MissingResourceException mre) { @@ -404,7 +421,7 @@ class TLexer { } case 'Q': { - saved_mode = mode; + savedMode = mode; mode = TLexer.MODE_ESCAPE; reread = true; break; @@ -476,7 +493,7 @@ class TLexer { if (index < pattern.length - 2) { // need not care about supplementary codepoints here - lookAhead = (pattern[nextIndex()] & 0x1f); + lookAhead = pattern[nextIndex()] & 0x1f; break; } else { throw new TPatternSyntaxException("", this.toString(), index); @@ -585,7 +602,7 @@ class TLexer { if (lookAhead >= 256) { // Erase auxiliary bit - lookAhead = (lookAhead & 0xff); + lookAhead = lookAhead & 0xff; flags = lookAhead; lookAhead = lookAhead << 16; lookAhead = CHAR_FLAGS | lookAhead; @@ -682,19 +699,26 @@ class TLexer { nextIndex(); char ch = 0; - while (index < pattern.length - 2 && (ch = pattern[nextIndex()]) != '}') { + while (index < pattern.length - 2) { + ch = pattern[nextIndex()]; + if (ch == '}') { + break; + } sb.append(ch); } - if (ch != '}') + if (ch != '}') { throw new TPatternSyntaxException("", this.toString(), index); + } } - if (sb.length() == 0) + if (sb.length() == 0) { throw new TPatternSyntaxException("", this.toString(), index); + } String res = sb.toString(); - if (res.length() == 1) + if (res.length() == 1) { return "Is" + res; + } return (res.length() > 3 && (res.startsWith("Is") || res.startsWith("In"))) ? res.substring(2) : res; } @@ -705,7 +729,11 @@ class TLexer { StringBuilder sb = new StringBuilder(4); int min = -1; int max = Integer.MAX_VALUE; - while (index < pattern.length && (ch = pattern[nextIndex()]) != '}') { + while (index < pattern.length) { + ch = pattern[nextIndex()]; + if (ch == '}') { + break; + } if (ch == ',' && min < 0) { try { min = Integer.parseInt(sb.toString(), 10); @@ -714,7 +742,7 @@ class TLexer { throw new TPatternSyntaxException("", this.toString(), index); } } else { - sb.append((char)ch); + sb.append((char) ch); } } if (ch != '}') { @@ -723,8 +751,9 @@ class TLexer { if (sb.length() > 0) { try { max = Integer.parseInt(sb.toString(), 10); - if (min < 0) + if (min < 0) { min = max; + } } catch (NumberFormatException nfe) { throw new TPatternSyntaxException("", this.toString(), index); } @@ -818,6 +847,7 @@ class TLexer { try { return Integer.parseInt(st.toString(), 16); } catch (NumberFormatException nfe) { + // do nothing } } @@ -834,18 +864,24 @@ class TLexer { int res; int length = pattern.length - 2; - switch (first = Character.digit(pattern[index], 8)) { + first = Character.digit(pattern[index], 8); + switch (first) { case -1: throw new TPatternSyntaxException("", this.toString(), index); default: { - if (first > 3) + if (first > 3) { max--; + } nextIndex(); res = first; } } - while (i < max && index < length && (first = Character.digit(pattern[index], 8)) >= 0) { + while (i < max && index < length) { + first = Character.digit(pattern[index], 8); + if (first < 0) { + break; + } res = res * 8 + first; nextIndex(); i++; @@ -938,19 +974,22 @@ class TLexer { int length = pattern.length - 2; index++; do { - while (index < length && Character.isWhitespace(pattern[index])) + while (index < length && Character.isWhitespace(pattern[index])) { index++; + } if (index < length && pattern[index] == '#') { index++; - while (index < length && !isLineSeparator(pattern[index])) + while (index < length && !isLineSeparator(pattern[index])) { index++; - } else + } + } else { return index; + } } while (true); } private boolean isLineSeparator(int ch) { - return (ch == '\n' || ch == '\r' || ch == '\u0085' || (ch | 1) == '\u2029'); + return ch == '\n' || ch == '\r' || ch == '\u0085' || (ch | 1) == '\u2029'; } /** @@ -975,21 +1014,21 @@ class TLexer { * @return canonical decomposition of ch. */ static int[] getHangulDecomposition(int ch) { - int SIndex = ch - SBase; + int sIndex = ch - SBase; - if (SIndex < 0 || SIndex >= SCount) { + if (sIndex < 0 || sIndex >= SCount) { return null; } else { - int L = LBase + SIndex / NCount; - int V = VBase + (SIndex % NCount) / TCount; - int T = SIndex % TCount; - int decomp[]; + int l = LBase + sIndex / NCount; + int v = VBase + (sIndex % NCount) / TCount; + int t = sIndex % TCount; + int[] decomp; - if (T == 0) { - decomp = new int[] { L, V }; + if (t == 0) { + decomp = new int[] { l, v }; } else { - T = TBase + T; - decomp = new int[] { L, V, T }; + t = TBase + t; + decomp = new int[] { l, v, t }; } return decomp; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowHighSurrogateRangeSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowHighSurrogateRangeSet.java index 09fc8d517..da6aadf36 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowHighSurrogateRangeSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowHighSurrogateRangeSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -89,7 +105,7 @@ class TLowHighSurrogateRangeSet extends TJointSet { protected TAbstractCharClass surrChars; - protected boolean alt = false; + protected boolean alt; public TLowHighSurrogateRangeSet(TAbstractCharClass surrChars, TAbstractSet next) { this.surrChars = surrChars.getInstance(); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowSurrogateCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowSurrogateCharSet.java index 9f5356505..46dc0a742 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowSurrogateCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TLowSurrogateCharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -149,15 +165,16 @@ class TLowSurrogateCharSet extends TJointSet { @Override public int find(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { - String testStr = (String)testString; + String testStr = (String) testString; int startStr = matchResult.getLeftBound(); int strLength = matchResult.getRightBound(); while (strIndex < strLength) { strIndex = testStr.indexOf(low, strIndex); - if (strIndex < 0) + if (strIndex < 0) { return -1; + } if (strIndex > startStr) { @@ -187,7 +204,7 @@ class TLowSurrogateCharSet extends TJointSet { public int findBack(int strIndex, int lastIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { int startStr = matchResult.getLeftBound(); - String testStr = (String)testString; + String testStr = (String) testString; while (lastIndex >= strIndex) { lastIndex = testStr.lastIndexOf(low, lastIndex); @@ -242,7 +259,7 @@ class TLowSurrogateCharSet extends TJointSet { } else if (set instanceof THighSurrogateCharSet) { return false; } else if (set instanceof TLowSurrogateCharSet) { - return ((TLowSurrogateCharSet)set).low == this.low; + return ((TLowSurrogateCharSet) set).low == this.low; } return true; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResult.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResult.java index 73ffa4d01..c3c1f0f1d 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResult.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResult.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java index ebf8ba377..9dc9b5a25 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -30,17 +46,17 @@ import java.util.Arrays; */ class TMatchResultImpl implements TMatchResult { - private int[] groupBounds = null; + private int[] groupBounds; - private int[] consumers = null; + private int[] consumers; - private int[] compQuantCounters = null; + private int[] compQuantCounters; - private CharSequence string = null; + private CharSequence string; - private int groupCount = 0; + private int groupCount; - private boolean valid = false; + private boolean valid; private int leftBound; @@ -48,13 +64,13 @@ class TMatchResultImpl implements TMatchResult { int startIndex; - private boolean transparentBounds = false; + private boolean transparentBounds; - private boolean anchoringBounds = false; + private boolean anchoringBounds; - boolean hitEnd = false; + boolean hitEnd; - boolean requireEnd = false; + boolean requireEnd; int previousMatch = -1; @@ -68,15 +84,16 @@ class TMatchResultImpl implements TMatchResult { this.consumers = new int[consumersCount]; Arrays.fill(consumers, -1); - if (compQuantCount > 0) + if (compQuantCount > 0) { this.compQuantCounters = new int[compQuantCount]; + } Arrays.fill(groupBounds, -1); reset(string, leftBound, rightBound); } TMatchResult cloneImpl() { - TMatchResultImpl res = new TMatchResultImpl(this.string, this.leftBound, this.rightBound, this.groupCount - 1, 0, - 0); + TMatchResultImpl res = new TMatchResultImpl(this.string, this.leftBound, this.rightBound, this.groupCount - 1, + 0, 0); res.valid = valid; if (valid) { @@ -127,16 +144,18 @@ class TMatchResultImpl implements TMatchResult { @Override public String group(int group) { - if (start(group) < 0) + if (start(group) < 0) { return null; + } return string.subSequence(start(group), end(group)).toString(); } String getGroupNoCheck(int group) { int st = getStart(group); int end = getEnd(group); - if ((end | st | (end - st)) < 0 || end > string.length()) + if ((end | st | (end - st)) < 0 || end > string.length()) { return null; + } return string.subSequence(st, end).toString(); } @@ -208,10 +227,12 @@ class TMatchResultImpl implements TMatchResult { Arrays.fill(groupBounds, -1); Arrays.fill(consumers, -1); - if (newSequence != null) + if (newSequence != null) { this.string = newSequence; - if (leftBound >= 0) + } + if (leftBound >= 0) { this.setBounds(leftBound, rightBound); + } this.startIndex = this.leftBound; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java index 49b10506e..0450f2548 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -48,17 +64,17 @@ import java.util.ArrayList; */ public final class TMatcher implements TMatchResult { - static int MODE_FIND = 1; + static final int MODE_FIND = 1; - static int MODE_MATCH = 1 << 1; + static final int MODE_MATCH = 1 << 1; - private TPattern pat = null; + private TPattern pat; - private TAbstractSet start = null; + private TAbstractSet start; - private CharSequence string = null; + private CharSequence string; - private TMatchResultImpl matchResult = null; + private TMatchResultImpl matchResult; // bounds private int leftBound = -1; @@ -66,13 +82,13 @@ public final class TMatcher implements TMatchResult { private int rightBound = -1; // replacements - private int appendPos = 0; + private int appendPos; - private String replacement = null; + private String replacement; - private String processedRepl = null; + private String processedRepl; - private ArrayList replacementParts = null; + private ArrayList replacementParts; /** * Appends a literal part of the input plus a replacement for the current @@ -379,15 +395,16 @@ public final class TMatcher implements TMatchResult { */ public boolean find() { int length = string.length(); - if (!hasTransparentBounds()) + if (!hasTransparentBounds()) { length = rightBound; + } if (matchResult.startIndex >= 0 && matchResult.mode() == TMatcher.MODE_FIND) { matchResult.startIndex = matchResult.end(); if (matchResult.end() == matchResult.start()) { matchResult.startIndex++; } - return matchResult.startIndex <= length ? find(matchResult.startIndex) : false; + return matchResult.startIndex <= length && find(matchResult.startIndex); } else { return find(leftBound); } @@ -447,15 +464,16 @@ public final class TMatcher implements TMatchResult { */ public static String quoteReplacement(String s) { // first check whether we have smth to quote - if (s.indexOf('\\') < 0 && s.indexOf('$') < 0) + if (s.indexOf('\\') < 0 && s.indexOf('$') < 0) { return s; + } StringBuilder res = new StringBuilder(s.length() * 2); char ch; int len = s.length(); for (int i = 0; i < len; i++) { - - switch (ch = s.charAt(i)) { + ch = s.charAt(i); + switch (ch) { case '$': res.append('\\'); res.append('$'); @@ -680,7 +698,8 @@ public final class TMatcher implements TMatchResult { this.string = cs; this.leftBound = 0; this.rightBound = string.length(); - matchResult = new TMatchResultImpl(cs, leftBound, rightBound, pat.groupCount(), pat.compCount(), pat.consCount()); + matchResult = new TMatchResultImpl(cs, leftBound, rightBound, pat.groupCount(), pat.compCount(), + pat.consCount()); } @Override @@ -689,8 +708,9 @@ public final class TMatcher implements TMatchResult { try { lastMatch = Integer.toString(start()); } catch (IllegalStateException e) { + // do nothing } - return "Regex[pattern=" + pat + " region=" + matchResult.getLeftBound() + "," + matchResult.getRightBound() + - " lastmatch=" + lastMatch + "]"; + return "Regex[pattern=" + pat + " region=" + matchResult.getLeftBound() + "," + matchResult.getRightBound() + + " lastmatch=" + lastMatch + "]"; } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java index d974a8b55..a3f163739 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,8 +51,9 @@ class TMultiLineEOLSet extends TAbstractSet { @Override public int matches(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { - int strDif = matchResult.hasAnchoringBounds() ? matchResult.getLeftBound() - strIndex : testString.length() - - strIndex; + int strDif = matchResult.hasAnchoringBounds() + ? matchResult.getLeftBound() - strIndex + : testString.length() - strIndex; char ch1; char ch2; if (strDif == 0) { @@ -75,8 +92,7 @@ class TMultiLineEOLSet extends TAbstractSet { @Override public boolean hasConsumed(TMatchResultImpl matchResult) { - int cons; - boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0); + boolean res = matchResult.getConsumed(consCounter) != 0; matchResult.setConsumed(consCounter, -1); return res; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineSOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineSOLSet.java index d4807dc72..c3ab5f154 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineSOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineSOLSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,9 +51,9 @@ class TMultiLineSOLSet extends TAbstractSet { @Override public int matches(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { - if (strIndex != matchResult.getRightBound() && - ((strIndex == 0 || (matchResult.hasAnchoringBounds() && strIndex == matchResult.getLeftBound())) || lt - .isAfterLineTerminator(testString.charAt(strIndex - 1), testString.charAt(strIndex)))) { + if (strIndex != matchResult.getRightBound() + && ((strIndex == 0 || (matchResult.hasAnchoringBounds() && strIndex == matchResult.getLeftBound())) + || lt.isAfterLineTerminator(testString.charAt(strIndex - 1), testString.charAt(strIndex)))) { return next.matches(strIndex, testString, matchResult); } return -1; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookAhead.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookAhead.java index f50d8d3d8..e1efa9fba 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookAhead.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookAhead.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -42,8 +58,9 @@ class TNegativeLookAhead extends TAtomicJointSet { for (int i = 0; i < size; i++) { TAbstractSet e = children.get(i); - if (e.matches(stringIndex, testString, matchResult) >= 0) + if (e.matches(stringIndex, testString, matchResult) >= 0) { return -1; + } } return next.matches(stringIndex, testString, matchResult); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookBehind.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookBehind.java index 037c88096..133f4496b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookBehind.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNegativeLookBehind.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapFSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapFSet.java index b6cddf3ef..f33106ae5 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapFSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapFSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapJointSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapJointSet.java index d70986076..66ac5776e 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapJointSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TNonCapJointSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java index 9a3cd673c..89a456459 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -118,28 +134,28 @@ public final class TPattern implements Serializable { /** * Bit mask that includes all defined match flags */ - static final int flagsBitMask = TPattern.UNIX_LINES | TPattern.CASE_INSENSITIVE | TPattern.COMMENTS | - TPattern.MULTILINE | TPattern.LITERAL | TPattern.DOTALL | TPattern.UNICODE_CASE | TPattern.CANON_EQ; + static final int flagsBitMask = TPattern.UNIX_LINES | TPattern.CASE_INSENSITIVE | TPattern.COMMENTS + | TPattern.MULTILINE | TPattern.LITERAL | TPattern.DOTALL | TPattern.UNICODE_CASE | TPattern.CANON_EQ; /** * Current pattern to be compiled; */ - private transient TLexer lexemes = null; + private transient TLexer lexemes; /** * Pattern compile flags; */ - private int flags = 0; + private int flags; /* * All backreferences that may be used in pattern. */ - transient private TFSet backRefs[] = new TFSet[BACK_REF_NUMBER]; + transient private TFSet[] backRefs = new TFSet[BACK_REF_NUMBER]; /* * Is true if backreferenced sets replacement is needed */ - transient private boolean needsBackRefReplacement = false; + transient private boolean needsBackRefReplacement; transient private int globalGroupIndex = -1; @@ -147,7 +163,7 @@ public final class TPattern implements Serializable { transient private int consCount = -1; - transient TAbstractSet start = null; + transient TAbstractSet start; /** * Returns a {@link TMatcher} for the {@code Pattern} and a given input. The @@ -332,12 +348,14 @@ public final class TPattern implements Serializable { */ private TAbstractSet processAlternations(TAbstractSet last) { TCharClass auxRange = new TCharClass(hasFlag(TPattern.CASE_INSENSITIVE), hasFlag(TPattern.UNICODE_CASE)); - while (!lexemes.isEmpty() && - lexemes.isLetter() && - (lexemes.lookAhead() == 0 || lexemes.lookAhead() == TLexer.CHAR_VERTICAL_BAR || lexemes.lookAhead() == TLexer.CHAR_RIGHT_PARENTHESIS)) { + while (!lexemes.isEmpty() + && lexemes.isLetter() + && (lexemes.lookAhead() == 0 || lexemes.lookAhead() == TLexer.CHAR_VERTICAL_BAR + || lexemes.lookAhead() == TLexer.CHAR_RIGHT_PARENTHESIS)) { auxRange.add(lexemes.next()); - if (lexemes.peek() == TLexer.CHAR_VERTICAL_BAR) + if (lexemes.peek() == TLexer.CHAR_VERTICAL_BAR) { lexemes.next(); + } } TAbstractSet rangeSet = processRangeSet(auxRange); rangeSet.setNext(last); @@ -467,24 +485,24 @@ public final class TPattern implements Serializable { private TAbstractSet processSequence() { StringBuffer substring = new StringBuffer(); - while (!lexemes.isEmpty() && - lexemes.isLetter() && - !lexemes.isHighSurrogate() && - !lexemes.isLowSurrogate() && - ((!lexemes.isNextSpecial() && lexemes.lookAhead() == 0) // end + while (!lexemes.isEmpty() + && lexemes.isLetter() + && !lexemes.isHighSurrogate() + && !lexemes.isLowSurrogate() + && ((!lexemes.isNextSpecial() && lexemes.lookAhead() == 0) // end // of // pattern - || - (!lexemes.isNextSpecial() && TLexer.isLetter(lexemes.lookAhead())) || - lexemes.lookAhead() == TLexer.CHAR_RIGHT_PARENTHESIS || - (lexemes.lookAhead() & 0x8000ffff) == TLexer.CHAR_LEFT_PARENTHESIS || - lexemes.lookAhead() == TLexer.CHAR_VERTICAL_BAR || lexemes.lookAhead() == TLexer.CHAR_DOLLAR)) { + || (!lexemes.isNextSpecial() && TLexer.isLetter(lexemes.lookAhead())) + || lexemes.lookAhead() == TLexer.CHAR_RIGHT_PARENTHESIS + || (lexemes.lookAhead() & 0x8000ffff) == TLexer.CHAR_LEFT_PARENTHESIS + || lexemes.lookAhead() == TLexer.CHAR_VERTICAL_BAR + || lexemes.lookAhead() == TLexer.CHAR_DOLLAR)) { int ch = lexemes.next(); if (Character.isSupplementaryCodePoint(ch)) { substring.append(Character.toChars(ch)); } else { - substring.append((char)ch); + substring.append((char) ch); } } if (!hasFlag(TPattern.CASE_INSENSITIVE)) { @@ -519,17 +537,17 @@ public final class TPattern implements Serializable { */ if ((curSymbIndex >= 0) && (curSymbIndex < TLexer.LCount)) { codePointsHangul = new char[TLexer.MAX_HANGUL_DECOMPOSITION_LENGTH]; - codePointsHangul[readCodePoints++] = (char)curSymb; + codePointsHangul[readCodePoints++] = (char) curSymb; curSymb = lexemes.peek(); curSymbIndex = curSymb - TLexer.VBase; if ((curSymbIndex >= 0) && (curSymbIndex < TLexer.VCount)) { - codePointsHangul[readCodePoints++] = (char)curSymb; + codePointsHangul[readCodePoints++] = (char) curSymb; lexemes.next(); curSymb = lexemes.peek(); curSymbIndex = curSymb - TLexer.TBase; if ((curSymbIndex >= 0) && (curSymbIndex < TLexer.TCount)) { - codePointsHangul[readCodePoints++] = (char)curSymb; + codePointsHangul[readCodePoints++] = (char) curSymb; lexemes.next(); // LVT syllable @@ -590,8 +608,8 @@ public final class TPattern implements Serializable { if (!lexemes.isEmpty() /* && !pattern.isQuantifier() */ - && (lexemes.peek() != TLexer.CHAR_RIGHT_PARENTHESIS || last instanceof TFinalSet) && - lexemes.peek() != TLexer.CHAR_VERTICAL_BAR && !lexemes.isLetter()) { + && (lexemes.peek() != TLexer.CHAR_RIGHT_PARENTHESIS || last instanceof TFinalSet) + && lexemes.peek() != TLexer.CHAR_VERTICAL_BAR && !lexemes.isLetter()) { cur = processQuantifier(last, cur); } } else if (lexemes.isHighSurrogate() || lexemes.isLowSurrogate()) { @@ -613,23 +631,21 @@ public final class TPattern implements Serializable { if (!lexemes.isEmpty() // && !pattern.isQuantifier() - && - (lexemes.peek() != TLexer.CHAR_RIGHT_PARENTHESIS || last instanceof TFinalSet) && - lexemes.peek() != TLexer.CHAR_VERTICAL_BAR) { + && (lexemes.peek() != TLexer.CHAR_RIGHT_PARENTHESIS || last instanceof TFinalSet) + && lexemes.peek() != TLexer.CHAR_VERTICAL_BAR) { TAbstractSet next = processSubExpression(last); if (cur instanceof TLeafQuantifierSet // TODO create personal UnifiedQuantifierSet for composite // quantifiers // to take into account Quantifier counters // //// - && - !(cur instanceof TCompositeQuantifierSet) && - !(cur instanceof TGroupQuantifierSet) && - !(cur instanceof TAltQuantifierSet) && !next.first(((TLeafQuantifierSet)cur).getInnerSet())) { - cur = new TUnifiedQuantifierSet((TLeafQuantifierSet)cur); + && !(cur instanceof TCompositeQuantifierSet) + && !(cur instanceof TGroupQuantifierSet) + && !(cur instanceof TAltQuantifierSet) && !next.first(((TLeafQuantifierSet) cur).getInnerSet())) { + cur = new TUnifiedQuantifierSet((TLeafQuantifierSet) cur); } - if (((char)next.getType()) == '+') { - cur.setNext(((TLeafQuantifierSet)next).getInnerSet()); + if (((char) next.getType()) == '+') { + cur.setNext(((TLeafQuantifierSet) next).getInnerSet()); } else { cur.setNext(next); } @@ -639,8 +655,8 @@ public final class TPattern implements Serializable { return null; } - if (((char)cur.getType()) == '+') { - return ((TQuantifierSet)cur).getInnerSet(); + if (((char) cur.getType()) == '+') { + return ((TQuantifierSet) cur).getInnerSet(); } else { return cur; } @@ -715,20 +731,20 @@ public final class TPattern implements Serializable { } case TLexer.QUANT_COMP: { - TCompositeGroupQuantifierSet q = new TCompositeGroupQuantifierSet((TQuantifier)lexemes.nextSpecial(), - term, last, TLexer.QUANT_ALT, ++compCount); + TCompositeGroupQuantifierSet q = new TCompositeGroupQuantifierSet( + (TQuantifier) lexemes.nextSpecial(), term, last, TLexer.QUANT_ALT, ++compCount); term.setNext(q); return q; } case TLexer.QUANT_COMP_P: { - return new TPosCompositeGroupQuantifierSet((TQuantifier)lexemes.nextSpecial(), term, last, + return new TPosCompositeGroupQuantifierSet((TQuantifier) lexemes.nextSpecial(), term, last, TLexer.QUANT_ALT, ++compCount); } case TLexer.QUANT_COMP_R: { TRelCompositeGroupQuantifierSet q = new TRelCompositeGroupQuantifierSet( - (TQuantifier)lexemes.nextSpecial(), term, last, TLexer.QUANT_ALT, ++compCount); + (TQuantifier) lexemes.nextSpecial(), term, last, TLexer.QUANT_ALT, ++compCount); term.setNext(q); return q; } @@ -738,8 +754,9 @@ public final class TPattern implements Serializable { } } else { TLeafSet leaf = null; - if (term != null) - leaf = (TLeafSet)term; + if (term != null) { + leaf = (TLeafSet) term; + } switch (quant) { case TLexer.QUANT_STAR: case TLexer.QUANT_PLUS: { @@ -781,15 +798,16 @@ public final class TPattern implements Serializable { } case TLexer.QUANT_COMP: { - return new TCompositeQuantifierSet((TQuantifier)lexemes.nextSpecial(), leaf, last, TLexer.QUANT_COMP); + return new TCompositeQuantifierSet((TQuantifier) lexemes.nextSpecial(), leaf, last, + TLexer.QUANT_COMP); } case TLexer.QUANT_COMP_P: { - return new TPossessiveCompositeQuantifierSet((TQuantifier)lexemes.nextSpecial(), leaf, last, + return new TPossessiveCompositeQuantifierSet((TQuantifier) lexemes.nextSpecial(), leaf, last, TLexer.QUANT_COMP_P); } case TLexer.QUANT_COMP_R: { - return new TReluctantCompositeQuantifierSet((TQuantifier)lexemes.nextSpecial(), leaf, last, + return new TReluctantCompositeQuantifierSet((TQuantifier) lexemes.nextSpecial(), leaf, last, TLexer.QUANT_COMP_R); } @@ -822,7 +840,7 @@ public final class TPattern implements Serializable { } lexemes.next(); } - } else + } else { switch (ch) { case TLexer.CHAR_LEFT_SQUARE_BRACKET: { lexemes.next(); @@ -833,8 +851,9 @@ public final class TPattern implements Serializable { } term = processRange(negative, last); - if (lexemes.peek() != TLexer.CHAR_RIGHT_SQUARE_BRACKET) + if (lexemes.peek() != TLexer.CHAR_RIGHT_SQUARE_BRACKET) { throw new TPatternSyntaxException("", lexemes.toString(), lexemes.getIndex()); + } lexemes.setMode(TLexer.MODE_PATTERN); lexemes.next(); break; @@ -949,13 +968,13 @@ public final class TPattern implements Serializable { } case 0: { - TAbstractCharClass cc = null; - if ((cc = (TAbstractCharClass)lexemes.peekSpecial()) != null) { + TAbstractCharClass cc = (TAbstractCharClass) lexemes.peekSpecial(); + if (cc != null) { term = processRangeSet(cc); } else if (!lexemes.isEmpty()) { // ch == 0 - term = new TCharSet((char)ch); + term = new TCharSet((char) ch); } else { term = new TEmptySet(last); break; @@ -977,11 +996,14 @@ public final class TPattern implements Serializable { term = new TEmptySet(last); } } else { - throw new TPatternSyntaxException((lexemes.isSpecial() ? lexemes.peekSpecial().toString() - : Character.toString((char)ch)), lexemes.toString(), lexemes.getIndex()); + throw new TPatternSyntaxException( + lexemes.isSpecial() ? lexemes.peekSpecial().toString() + : Character.toString((char) ch), + lexemes.toString(), lexemes.getIndex()); } } } + } } while (ch == TLexer.CHAR_FLAGS); return term; } @@ -1004,12 +1026,17 @@ public final class TPattern implements Serializable { boolean notClosed = false; boolean firstInClass = true; - while (!lexemes.isEmpty() && (notClosed = (lexemes.peek()) != TLexer.CHAR_RIGHT_SQUARE_BRACKET || firstInClass)) { + while (!lexemes.isEmpty()) { + notClosed = lexemes.peek() != TLexer.CHAR_RIGHT_SQUARE_BRACKET || firstInClass; + if (!notClosed) { + break; + } switch (lexemes.peek()) { case TLexer.CHAR_RIGHT_SQUARE_BRACKET: { - if (buffer >= 0) + if (buffer >= 0) { res.add(buffer); + } buffer = ']'; lexemes.next(); break; @@ -1026,18 +1053,20 @@ public final class TPattern implements Serializable { negative = true; } - if (intersection) + if (intersection) { res.intersection(processRangeExpression(negative)); - else + } else { res.union(processRangeExpression(negative)); + } intersection = false; lexemes.next(); break; } case TLexer.CHAR_AMPERSAND: { - if (buffer >= 0) + if (buffer >= 0) { res.add(buffer); + } buffer = lexemes.next(); /* @@ -1075,11 +1104,12 @@ public final class TPattern implements Serializable { } case TLexer.CHAR_HYPHEN: { - if (firstInClass || lexemes.lookAhead() == TLexer.CHAR_RIGHT_SQUARE_BRACKET || - lexemes.lookAhead() == TLexer.CHAR_LEFT_SQUARE_BRACKET || buffer < 0) { + if (firstInClass || lexemes.lookAhead() == TLexer.CHAR_RIGHT_SQUARE_BRACKET + || lexemes.lookAhead() == TLexer.CHAR_LEFT_SQUARE_BRACKET || buffer < 0) { // treat hypen as normal character - if (buffer >= 0) + if (buffer >= 0) { res.add(buffer); + } buffer = '-'; lexemes.next(); // range @@ -1087,9 +1117,9 @@ public final class TPattern implements Serializable { lexemes.next(); int cur = lexemes.peek(); - if (!lexemes.isSpecial() && - (cur >= 0 || lexemes.lookAhead() == TLexer.CHAR_RIGHT_SQUARE_BRACKET || - lexemes.lookAhead() == TLexer.CHAR_LEFT_SQUARE_BRACKET || buffer < 0)) { + if (!lexemes.isSpecial() + && (cur >= 0 || lexemes.lookAhead() == TLexer.CHAR_RIGHT_SQUARE_BRACKET + || lexemes.lookAhead() == TLexer.CHAR_LEFT_SQUARE_BRACKET || buffer < 0)) { try { if (!TLexer.isLetter(cur)) { @@ -1110,17 +1140,19 @@ public final class TPattern implements Serializable { } case TLexer.CHAR_CARET: { - if (buffer >= 0) + if (buffer >= 0) { res.add(buffer); + } buffer = '^'; lexemes.next(); break; } case 0: { - if (buffer >= 0) + if (buffer >= 0) { res.add(buffer); - TAbstractCharClass cs = (TAbstractCharClass)lexemes.peekSpecial(); + } + TAbstractCharClass cs = (TAbstractCharClass) lexemes.peekSpecial(); if (cs != null) { res.add(cs); buffer = -1; @@ -1133,8 +1165,9 @@ public final class TPattern implements Serializable { } default: { - if (buffer >= 0) + if (buffer >= 0) { res.add(buffer); + } buffer = lexemes.next(); break; } @@ -1145,8 +1178,9 @@ public final class TPattern implements Serializable { if (notClosed) { throw new TPatternSyntaxException("", pattern(), lexemes.getIndex() - 1); } - if (buffer >= 0) + if (buffer >= 0) { res.add(buffer); + } return res; } @@ -1156,20 +1190,20 @@ public final class TPattern implements Serializable { if (hasFlag(TPattern.CASE_INSENSITIVE)) { if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { - return new TCICharSet((char)ch); + return new TCICharSet((char) ch); } else if (hasFlag(TPattern.UNICODE_CASE) && ch > 128) { if (isSupplCodePoint) { return new TUCISupplCharSet(ch); } else if (TLexer.isLowSurrogate(ch)) { // we need no UCILowSurrogateCharSet - return new TLowSurrogateCharSet((char)ch); + return new TLowSurrogateCharSet((char) ch); } else if (TLexer.isHighSurrogate(ch)) { // we need no UCIHighSurrogateCharSet - return new THighSurrogateCharSet((char)ch); + return new THighSurrogateCharSet((char) ch); } else { - return new TUCICharSet((char)ch); + return new TUCICharSet((char) ch); } } } @@ -1177,11 +1211,11 @@ public final class TPattern implements Serializable { if (isSupplCodePoint) { return new TSupplCharSet(ch); } else if (TLexer.isLowSurrogate(ch)) { - return new TLowSurrogateCharSet((char)ch); + return new TLowSurrogateCharSet((char) ch); } else if (TLexer.isHighSurrogate(ch)) { - return new THighSurrogateCharSet((char)ch); + return new THighSurrogateCharSet((char) ch); } else { - return new TCharSet((char)ch); + return new TCharSet((char) ch); } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPatternSyntaxException.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPatternSyntaxException.java index 6ad5dbd51..48f8d6378 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPatternSyntaxException.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPatternSyntaxException.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosAltGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosAltGroupQuantifierSet.java index 1681a61d4..c4e5130bd 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosAltGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosAltGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosCompositeGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosCompositeGroupQuantifierSet.java index 0614a1a24..41d2ae45b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosCompositeGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosCompositeGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -39,7 +55,11 @@ class TPosCompositeGroupQuantifierSet extends TCompositeGroupQuantifierSet { int counter = 0; int max = quantifier.max(); - while ((nextIndex = innerSet.matches(stringIndex, testString, matchResult)) > stringIndex && counter < max) { + while (true) { + nextIndex = innerSet.matches(stringIndex, testString, matchResult); + if (nextIndex <= stringIndex || counter >= max) { + break; + } counter++; stringIndex = nextIndex; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosPlusGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosPlusGroupQuantifierSet.java index 9c0be3f4e..ec96f2f22 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosPlusGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPosPlusGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -34,8 +50,8 @@ class TPosPlusGroupQuantifierSet extends TGroupQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - int nextIndex; - if ((nextIndex = innerSet.matches(stringIndex, testString, matchResult)) < 0) { + int nextIndex = innerSet.matches(stringIndex, testString, matchResult); + if (nextIndex < 0) { return -1; } else if (nextIndex > stringIndex) { stringIndex = nextIndex; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookAhead.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookAhead.java index f6a97f237..f496c9e29 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookAhead.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookAhead.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookBehind.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookBehind.java index 2cbacb23f..64bc7fca9 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookBehind.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPositiveLookBehind.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveAltQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveAltQuantifierSet.java index c95cdbddc..c10f7bb4c 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveAltQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveAltQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -34,9 +50,11 @@ class TPossessiveAltQuantifierSet extends TAltQuantifierSet { public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int shift = 0; - if (stringIndex + leaf.charCount() <= matchResult.getRightBound() && - (shift = leaf.accepts(stringIndex, testString)) >= 1) { - stringIndex += shift; + if (stringIndex + leaf.charCount() <= matchResult.getRightBound()) { + shift = leaf.accepts(stringIndex, testString); + if (shift >= 1) { + stringIndex += shift; + } } return next.matches(stringIndex, testString, matchResult); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveCompositeQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveCompositeQuantifierSet.java index bbce17013..78c178d92 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveCompositeQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveCompositeQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -50,8 +66,11 @@ class TPossessiveCompositeQuantifierSet extends TCompositeQuantifierSet { for (; i < max; i++) { int shift; - if (stringIndex + leaf.charCount() > matchResult.getRightBound() || - (shift = leaf.accepts(stringIndex, testString)) < 1) { + if (stringIndex + leaf.charCount() > matchResult.getRightBound()) { + break; + } + shift = leaf.accepts(stringIndex, testString); + if (shift < 1) { break; } stringIndex += shift; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveGroupQuantifierSet.java index 5b1beef96..cd1e9b877 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveQuantifierSet.java index 256a70e3a..6bacfa643 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPossessiveQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -34,8 +50,11 @@ class TPossessiveQuantifierSet extends TLeafQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int shift = 0; - while (stringIndex + leaf.charCount() <= matchResult.getRightBound() && - (shift = leaf.accepts(stringIndex, testString)) >= 1) { + while (stringIndex + leaf.charCount() <= matchResult.getRightBound()) { + shift = leaf.accepts(stringIndex, testString); + if (shift < 1) { + break; + } stringIndex += shift; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPreviousMatch.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPreviousMatch.java index 7e0940bbb..b8dd48020 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPreviousMatch.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TPreviousMatch.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifier.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifier.java index 711903d4e..8d8a11c3a 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifier.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifier.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -33,10 +49,11 @@ class TQuantifier extends TSpecialToken implements Cloneable { private int max; - private int counter = 0; + private int counter; public TQuantifier(int min) { - this.min = this.max = min; + this.min = min; + this.max = min; } public TQuantifier(int min, int max) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifierSet.java index a18289ed2..8307fc792 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -118,7 +134,7 @@ abstract class TQuantifierSet extends TAbstractSet { /* * Add here code to do during the pass */ - if (innerSet instanceof TSingleSet && ((TFSet)((TJointSet)innerSet).fSet).isBackReferenced) { + if (innerSet instanceof TSingleSet && ((TFSet) ((TJointSet) innerSet).fSet).isBackReferenced) { innerSet = innerSet.next; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRangeSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRangeSet.java index b3c2c16b7..89cab0a7e 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRangeSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRangeSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -30,7 +46,7 @@ class TRangeSet extends TLeafSet { private TAbstractCharClass chars; - private boolean alt = false; + private boolean alt; public TRangeSet(TAbstractCharClass cs, TAbstractSet next) { super(next); @@ -56,11 +72,11 @@ class TRangeSet extends TLeafSet { @Override public boolean first(TAbstractSet set) { if (set instanceof TCharSet) { - return TAbstractCharClass.intersects(chars, ((TCharSet)set).getChar()); + return TAbstractCharClass.intersects(chars, ((TCharSet) set).getChar()); } else if (set instanceof TRangeSet) { - return TAbstractCharClass.intersects(chars, ((TRangeSet)set).chars); + return TAbstractCharClass.intersects(chars, ((TRangeSet) set).chars); } else if (set instanceof TSupplRangeSet) { - return TAbstractCharClass.intersects(chars, ((TSupplRangeSet)set).getChars()); + return TAbstractCharClass.intersects(chars, ((TSupplRangeSet) set).getChars()); } else if (set instanceof TSupplCharSet) { return false; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelAltGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelAltGroupQuantifierSet.java index 9085f932b..f47a512e0 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelAltGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelAltGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -34,15 +50,12 @@ class TRelAltGroupQuantifierSet extends TAltGroupQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - if (!innerSet.hasConsumed(matchResult)) + if (!innerSet.hasConsumed(matchResult)) { return next.matches(stringIndex, testString, matchResult); + } int nextIndex = next.matches(stringIndex, testString, matchResult); - if (nextIndex < 0) { - return innerSet.matches(stringIndex, testString, matchResult); - } else { - return nextIndex; - } + return nextIndex < 0 ? innerSet.matches(stringIndex, testString, matchResult) : nextIndex; } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelCompositeGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelCompositeGroupQuantifierSet.java index c29d677bd..7761c44d2 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelCompositeGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TRelCompositeGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -36,8 +52,9 @@ class TRelCompositeGroupQuantifierSet extends TCompositeGroupQuantifierSet { public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int enterCounter = matchResult.getEnterCounter(setCounter); - if (!innerSet.hasConsumed(matchResult)) + if (!innerSet.hasConsumed(matchResult)) { return next.matches(stringIndex, testString, matchResult); + } // can't go inner set; if (enterCounter >= quantifier.max()) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantAltQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantAltQuantifierSet.java index a10817588..06a6f30e4 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantAltQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantAltQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,9 +48,9 @@ class TReluctantAltQuantifierSet extends TAltQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - int shift; + int shift = next.matches(stringIndex, testString, matchResult); - if ((shift = next.matches(stringIndex, testString, matchResult)) >= 0) { + if (shift >= 0) { return shift; } else { return innerSet.matches(stringIndex, testString, matchResult); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantCompositeQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantCompositeQuantifierSet.java index dc1e3630c..7209f75ed 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantCompositeQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantCompositeQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantGroupQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantGroupQuantifierSet.java index 5f1720695..cdf901e88 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantGroupQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantGroupQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,8 +48,9 @@ class TReluctantGroupQuantifierSet extends TGroupQuantifierSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - if (!innerSet.hasConsumed(matchResult)) + if (!innerSet.hasConsumed(matchResult)) { return next.matches(stringIndex, testString, matchResult); + } int res = next.matches(stringIndex, testString, matchResult); if (res < 0) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantQuantifierSet.java index f35914797..b5648f649 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TReluctantQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java index 2e08d47d5..2f6ee4df7 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSequenceSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSequenceSet.java index d63d1aa92..79a2d55ef 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSequenceSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSequenceSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -36,7 +52,7 @@ package org.teavm.classlib.java.util.regex; */ class TSequenceSet extends TLeafSet { - private String string = null; + private String string; private IntHash leftToRight; @@ -68,10 +84,12 @@ class TSequenceSet extends TLeafSet { while (strIndex <= strLength) { strIndex = indexOf(testString, strIndex, strLength); - if (strIndex < 0) + if (strIndex < 0) { return -1; - if (next.matches(strIndex + charCount, testString, matchResult) >= 0) + } + if (next.matches(strIndex + charCount, testString, matchResult) >= 0) { return strIndex; + } strIndex++; } @@ -86,10 +104,12 @@ class TSequenceSet extends TLeafSet { while (lastIndex >= strIndex) { lastIndex = lastIndexOf(testString, strIndex, lastIndex); - if (lastIndex < 0) + if (lastIndex < 0) { return -1; - if (next.matches(lastIndex + charCount, testString, matchResult) >= 0) + } + if (next.matches(lastIndex + charCount, testString, matchResult) >= 0) { return lastIndex; + } lastIndex--; } @@ -112,12 +132,10 @@ class TSequenceSet extends TLeafSet { return ((TSupplRangeSet) set).contains(string.charAt(0)) || ((string.length() > 1) && ((TSupplRangeSet) set).contains(Character .toCodePoint(string.charAt(0), string.charAt(1)))); - } else if ((set instanceof TSupplCharSet)) { - return (string.length() > 1) - ? ((TSupplCharSet) set).getCodePoint() - == Character.toCodePoint(string.charAt(0), - string.charAt(1)) - : false; + } else if (set instanceof TSupplCharSet) { + return (string.length() > 1) + && ((TSupplCharSet) set).getCodePoint() == Character.toCodePoint(string.charAt(0), + string.charAt(1)); } return true; @@ -141,8 +159,8 @@ class TSequenceSet extends TLeafSet { protected int lastIndexOf(CharSequence str, int to, int from) { int first = string.charAt(0); int size = str.length(); - int delta; - int i = ((delta = size - from - charCount) > 0) ? from : from + delta; + int delta = size - from - charCount; + int i = delta > 0 ? from : from + delta; while (i >= to) { char ch = str.charAt(i); @@ -157,14 +175,16 @@ class TSequenceSet extends TLeafSet { protected boolean startsWith(CharSequence str, int from) { for (int i = 0; i < charCount; i++) { - if (str.charAt(i + from) != string.charAt(i)) + if (str.charAt(i + from) != string.charAt(i)) { return false; + } } return true; } static class IntHash { - int[] table, values; + int[] table; + int[] values; int mask; @@ -186,7 +206,7 @@ class TSequenceSet extends TLeafSet { for (;;) { if (table[hashCode] == 0 // empty - || table[hashCode] == key) {// rewrite + || table[hashCode] == key) { // rewrite table[hashCode] = key; values[hashCode] = value; return; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSingleSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSingleSet.java index bcfae940d..c5164be36 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSingleSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSingleSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -50,16 +66,18 @@ class TSingleSet extends TJointSet { @Override public int find(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int res = kid.find(stringIndex, testString, matchResult); - if (res >= 0) + if (res >= 0) { matchResult.setStart(groupIndex, res); + } return res; } @Override public int findBack(int stringIndex, int lastIndex, CharSequence testString, TMatchResultImpl matchResult) { int res = kid.findBack(stringIndex, lastIndex, testString, matchResult); - if (res >= 0) + if (res >= 0) { matchResult.setStart(groupIndex, res); + } return res; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSpecialToken.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSpecialToken.java index 59b9a4ae0..538ed49ff 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSpecialToken.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSpecialToken.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplCharSet.java index d0979c7bd..1adaec99f 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplCharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -90,9 +106,9 @@ class TSupplCharSet extends TLeafSet { /* * UTF-16 encoding of this supplementary codepoint */ - private char high = 0; + private char high; - private char low = 0; + private char low; // int value of this supplementary codepoint private int ch; @@ -121,13 +137,14 @@ class TSupplCharSet extends TLeafSet { public int find(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { - String testStr = (String)testString; + String testStr = (String) testString; int strLength = matchResult.getRightBound(); while (strIndex < strLength) { strIndex = testStr.indexOf(high, strIndex); - if (strIndex < 0) + if (strIndex < 0) { return -1; + } strIndex++; if (strIndex < strLength) { @@ -149,7 +166,7 @@ class TSupplCharSet extends TLeafSet { public int findBack(int strIndex, int lastIndex, CharSequence testString, TMatchResultImpl matchResult) { if (testString instanceof String) { - String testStr = (String)testString; + String testStr = (String) testString; while (lastIndex >= strIndex) { lastIndex = testStr.lastIndexOf(low, lastIndex); @@ -182,9 +199,9 @@ class TSupplCharSet extends TLeafSet { @Override public boolean first(TAbstractSet set) { if (set instanceof TSupplCharSet) { - return ((TSupplCharSet)set).getCodePoint() == ch; + return ((TSupplCharSet) set).getCodePoint() == ch; } else if (set instanceof TSupplRangeSet) { - return ((TSupplRangeSet)set).contains(ch); + return ((TSupplRangeSet) set).contains(ch); } else if (set instanceof TCharSet) { return false; } else if (set instanceof TRangeSet) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java index eca75c1a5..3c7d81dd6 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -91,7 +107,7 @@ class TSupplRangeSet extends TJointSet { protected TAbstractCharClass chars; - protected boolean alt = false; + protected boolean alt; public TSupplRangeSet(TAbstractCharClass cs, TAbstractSet next) { this.chars = cs.getInstance(); @@ -112,8 +128,11 @@ class TSupplRangeSet extends TJointSet { if (stringIndex < strLength) { char high = testString.charAt(stringIndex++); - if (contains(high) && (offset = next.matches(stringIndex, testString, matchResult)) > 0) { - return offset; + if (contains(high)) { + offset = next.matches(stringIndex, testString, matchResult); + if (offset > 0) { + return offset; + } } if (stringIndex < strLength) { @@ -140,13 +159,13 @@ class TSupplRangeSet extends TJointSet { @Override public boolean first(TAbstractSet set) { if (set instanceof TSupplCharSet) { - return TAbstractCharClass.intersects(chars, ((TSupplCharSet)set).getCodePoint()); + return TAbstractCharClass.intersects(chars, ((TSupplCharSet) set).getCodePoint()); } else if (set instanceof TCharSet) { - return TAbstractCharClass.intersects(chars, ((TCharSet)set).getChar()); + return TAbstractCharClass.intersects(chars, ((TCharSet) set).getChar()); } else if (set instanceof TSupplRangeSet) { - return TAbstractCharClass.intersects(chars, ((TSupplRangeSet)set).chars); + return TAbstractCharClass.intersects(chars, ((TSupplRangeSet) set).chars); } else if (set instanceof TRangeSet) { - return TAbstractCharClass.intersects(chars, ((TRangeSet)set).getChars()); + return TAbstractCharClass.intersects(chars, ((TRangeSet) set).getChars()); } return true; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIBackReferenceSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIBackReferenceSet.java index 0cb8693aa..8c4a795ea 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIBackReferenceSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIBackReferenceSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -37,8 +53,9 @@ class TUCIBackReferenceSet extends TCIBackReferenceSet { public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { String group = getString(matchResult); - if (group == null || (stringIndex + group.length()) > matchResult.getRightBound()) + if (group == null || (stringIndex + group.length()) > matchResult.getRightBound()) { return -1; + } for (int i = 0; i < group.length(); i++) { if (Character.toLowerCase(Character.toUpperCase(group.charAt(i))) != Character.toLowerCase(Character diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCICharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCICharSet.java index 30a1e4bff..2be7c8dcf 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCICharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCICharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIDecomposedCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIDecomposedCharSet.java index ab292cec5..874739595 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIDecomposedCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIDecomposedCharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,7 +40,7 @@ package org.teavm.classlib.java.util.regex; * CANON_EQ flag of Pattern class * is specified. */ -class TUCIDecomposedCharSet extends TDecomposedCharSet{ +class TUCIDecomposedCharSet extends TDecomposedCharSet { /* * Just only a stub diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIRangeSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIRangeSet.java index 64f66cde5..892d44468 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIRangeSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCIRangeSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -31,7 +47,7 @@ class TUCIRangeSet extends TLeafSet { private TAbstractCharClass chars; - private boolean alt = false; + private boolean alt; public TUCIRangeSet(TAbstractCharClass cs, TAbstractSet next) { super(next); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISequenceSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISequenceSet.java index 63154566f..d0d70e299 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISequenceSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISequenceSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -27,7 +43,7 @@ package org.teavm.classlib.java.util.regex; */ class TUCISequenceSet extends TLeafSet { - private String string = null; + private String string; TUCISequenceSet(StringBuffer substring) { StringBuilder res = new StringBuilder(); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplCharSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplCharSet.java index d60eb446d..a984db399 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplCharSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplCharSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplRangeSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplRangeSet.java index 74ceedb6c..98dae2ca2 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplRangeSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUCISupplRangeSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUEOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUEOLSet.java index 66eab770e..773dbdb3d 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUEOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUEOLSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -53,8 +69,7 @@ final class TUEOLSet extends TAbstractSet { @Override public boolean hasConsumed(TMatchResultImpl matchResult) { - int cons; - boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0); + boolean res = matchResult.getConsumed(consCounter) != 0; matchResult.setConsumed(consCounter, -1); return res; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUMultiLineEOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUMultiLineEOLSet.java index 067774d25..e972f834b 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUMultiLineEOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUMultiLineEOLSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,8 +51,9 @@ class TUMultiLineEOLSet extends TAbstractSet { @Override public int matches(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { - int strDif = matchResult.hasAnchoringBounds() ? matchResult.getRightBound() - strIndex : testString.length() - - strIndex; + int strDif = matchResult.hasAnchoringBounds() + ? matchResult.getRightBound() - strIndex + : testString.length() - strIndex; if (strDif <= 0) { matchResult.setConsumed(consCounter, 0); return next.matches(strIndex, testString, matchResult); @@ -49,8 +66,7 @@ class TUMultiLineEOLSet extends TAbstractSet { @Override public boolean hasConsumed(TMatchResultImpl matchResult) { - int cons; - boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0); + boolean res = matchResult.getConsumed(consCounter) != 0; matchResult.setConsumed(consCounter, -1); return res; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategory.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategory.java index de4ef93d4..7a466ec23 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategory.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategory.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategoryScope.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategoryScope.java index 3f7fb4aba..4f668ee36 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategoryScope.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnicodeCategoryScope.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnifiedQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnifiedQuantifierSet.java index 832acab8c..9b654624d 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnifiedQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TUnifiedQuantifierSet.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -33,16 +49,17 @@ class TUnifiedQuantifierSet extends TLeafQuantifierSet { } public TUnifiedQuantifierSet(TLeafQuantifierSet quant) { - super((TLeafSet)quant.getInnerSet(), quant.getNext(), quant.getType()); + super((TLeafSet) quant.getInnerSet(), quant.getNext(), quant.getType()); innerSet.setNext(this); } @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { - while (stringIndex + leaf.charCount() <= matchResult.getRightBound() && - leaf.accepts(stringIndex, testString) > 0) + while (stringIndex + leaf.charCount() <= matchResult.getRightBound() + && leaf.accepts(stringIndex, testString) > 0) { stringIndex += leaf.charCount(); + } return next.matches(stringIndex, testString, matchResult); } @@ -50,8 +67,9 @@ class TUnifiedQuantifierSet extends TLeafQuantifierSet { @Override public int find(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int startSearch = next.find(stringIndex, testString, matchResult); - if (startSearch < 0) + if (startSearch < 0) { return -1; + } int newSearch = startSearch - leaf.charCount(); while (newSearch >= stringIndex && leaf.accepts(newSearch, testString) > 0) { startSearch = newSearch; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TWordBoundary.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TWordBoundary.java index 369be8878..99821961c 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TWordBoundary.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TWordBoundary.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -64,15 +80,18 @@ class TWordBoundary extends TAbstractSet { } private boolean isSpace(char ch, int index, int leftBound, CharSequence testString) { - if (Character.isLetterOrDigit(ch) || ch == '_') + if (Character.isLetterOrDigit(ch) || ch == '_') { return false; + } if (Character.getType(ch) == Character.NON_SPACING_MARK) { for (; --index >= leftBound;) { ch = testString.charAt(index); - if (Character.isLetterOrDigit(ch)) + if (Character.isLetterOrDigit(ch)) { return false; - if (Character.getType(ch) != Character.NON_SPACING_MARK) + } + if (Character.getType(ch) != Character.NON_SPACING_MARK) { return true; + } } } return true;