From 91a7a9ba229469da2735636167bcafd2e99646c7 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Mon, 17 Mar 2014 00:53:22 +0400 Subject: [PATCH] Adds java.lang.String methods. Makes intern on all string constants. --- .../org/teavm/classlib/java/lang/TString.java | 52 +++++++++++++++++++ .../teavm/classlib/java/lang/StringTest.java | 10 ++++ .../java/org/teavm/javascript/Renderer.java | 4 +- .../src/main/java/org/teavm/vm/TeaVM.java | 4 ++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java index 5ac53c3be..f4cdfdd41 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java @@ -19,6 +19,9 @@ import org.teavm.classlib.impl.charset.*; import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.io.TUnsupportedEncodingException; import org.teavm.classlib.java.util.TArrays; +import org.teavm.classlib.java.util.TComparator; +import org.teavm.classlib.java.util.THashMap; +import org.teavm.classlib.java.util.TMap; import org.teavm.dependency.PluggableDependency; import org.teavm.javascript.ni.InjectedBy; import org.teavm.javascript.ni.Rename; @@ -28,8 +31,14 @@ import org.teavm.javascript.ni.Rename; * @author Alexey Andreev */ public class TString extends TObject implements TSerializable, TComparable, TCharSequence { + public static final TComparator CASE_INSENSITIVE_ORDER = new TComparator() { + @Override public int compare(TString o1, TString o2) { + return o1.compareToIgnoreCase(o2); + } + }; private char[] characters; private transient int hashCode; + private static TMap pool = new THashMap<>(); public TString() { this.characters = new char[0]; @@ -183,6 +192,21 @@ public class TString extends TObject implements TSerializable, TComparable length()) { return false; @@ -548,4 +572,32 @@ public class TString extends TObject implements TSerializable, TComparable