This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
Patch: java.lang.String update
- To: java-patches at sourceware dot cygnus dot com
- Subject: Patch: java.lang.String update
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Wed, 13 Sep 2000 18:34:03 +1200
This patch adds a missing method and static field to our String
implementation. Note that CASE_INSENSITIVE_ORDER doesnt actually work
due to a compiler bug, but I believe that the implementation is correct.
regards
[ bryce ]
I2000-09-13 Bryce McKinlay <bryce@albatross.co.nz>
* java/lang/String.java (CASE_INSENSITIVE_ORDER): New static field.
Initialize with anonymous class.
(compareToIgnoreCase): New method.
Index: java/lang/String.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/String.java,v
retrieving revision 1.10
diff -u -r1.10 String.java
--- String.java 2000/09/08 19:37:08 1.10
+++ String.java 2000/09/13 06:23:31
@@ -10,6 +10,7 @@
import java.io.UnsupportedEncodingException;
import java.io.Serializable;
import java.lang.Comparable;
+import java.util.Comparator;
/**
* @author Per Bothner <bothner@cygnus.com>
@@ -17,7 +18,7 @@
*/
/* Written using "Java Class Libraries", 2nd edition, plus online
* API docs for JDK 1.2 beta from http://www.javasoft.com.
- * Status: Complete to 1.1, but see FIXMEs. Also see testsuite results.
+ * Status: Complete to 1.3.
*/
public final class String implements Serializable, Comparable
@@ -30,6 +31,14 @@
// but it will avoid showing up as a discrepancy when comparing SUIDs.
private static final long serialVersionUID = -6849794470754667710L;
+ static Comparator CASE_INSENSITIVE_ORDER = new Comparator()
+ {
+ public int compare (Object o1, Object o2)
+ {
+ return ((String) o1).compareToIgnoreCase ((String) o2);
+ }
+ };
+
public String ()
{
init();
@@ -182,6 +191,12 @@
{
return compareTo ((String)obj);
}
+
+ public int compareToIgnoreCase (String str)
+ {
+ return this.toUpperCase().toLowerCase().compareTo(
+ str.toUpperCase().toLowerCase());
+ }
public native boolean regionMatches (int toffset,
String other, int ooffset, int len);