Add regex methods into java.lang.String. Add group index checking into

java.util.regex.Matcher
This commit is contained in:
Alexey Andreev 2014-10-12 13:50:56 +04:00
parent 28251840ec
commit 78f4f7a1ff
2 changed files with 17 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import org.teavm.classlib.java.util.TArrays;
import org.teavm.classlib.java.util.TComparator; import org.teavm.classlib.java.util.TComparator;
import org.teavm.classlib.java.util.THashMap; import org.teavm.classlib.java.util.THashMap;
import org.teavm.classlib.java.util.TMap; import org.teavm.classlib.java.util.TMap;
import org.teavm.classlib.java.util.regex.TPattern;
import org.teavm.dependency.PluggableDependency; import org.teavm.dependency.PluggableDependency;
import org.teavm.javascript.ni.InjectedBy; import org.teavm.javascript.ni.InjectedBy;
import org.teavm.javascript.ni.Rename; import org.teavm.javascript.ni.Rename;
@ -613,4 +614,16 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
} }
return interned; return interned;
} }
public boolean matches(String regex) {
return TPattern.matches(regex, this.toString());
}
public String[] split(String regex) {
return TPattern.compile(regex).split(this.toString());
}
public String[] split(String regex, int limit) {
return TPattern.compile(regex).split(this.toString(), limit);
}
} }

View File

@ -316,6 +316,10 @@ public final class TMatcher implements TMatchResult {
*/ */
@Override @Override
public String group(int group) { public String group(int group) {
if (group < 0 || group > matchResult.groupCount()) {
throw new IndexOutOfBoundsException("Index " + group + " if out of range [0; " +
matchResult.groupCount() + ")");
}
return matchResult.group(group); return matchResult.group(group);
} }