mirror of
https://github.com/corda/corda.git
synced 2025-01-16 09:50:11 +00:00
Make String.compare() match the Java specification
This commit is contained in:
parent
60eeb73e0f
commit
8a4d3effe0
@ -89,36 +89,37 @@ public final class String implements Comparable<String> {
|
||||
public int compareTo(String s) {
|
||||
if (this == s) return 0;
|
||||
|
||||
int d = length - s.length;
|
||||
if (d != 0) {
|
||||
return d;
|
||||
} else {
|
||||
for (int i = 0; i < length; ++i) {
|
||||
d = charAt(i) - s.charAt(i);
|
||||
if (d != 0) {
|
||||
return d;
|
||||
int idx = 0;
|
||||
int result;
|
||||
|
||||
int end = (length < s.length ? length : s.length);
|
||||
|
||||
while (idx < end) {
|
||||
if ((result = charAt(idx) - s.charAt(idx)) != 0) {
|
||||
return result;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return length - s.length;
|
||||
}
|
||||
|
||||
public int compareToIgnoreCase(String s) {
|
||||
if (this == s) return 0;
|
||||
|
||||
int d = length - s.length;
|
||||
if (d != 0) {
|
||||
return d;
|
||||
} else {
|
||||
for (int i = 0; i < length; ++i) {
|
||||
d = Character.toLowerCase(charAt(i))
|
||||
- Character.toLowerCase(s.charAt(i));
|
||||
if (d != 0) {
|
||||
return d;
|
||||
int idx = 0;
|
||||
int result;
|
||||
|
||||
int end = (length < s.length ? length : s.length);
|
||||
|
||||
while (idx < end) {
|
||||
if ((result =
|
||||
Character.toLowerCase(charAt(idx)) -
|
||||
Character.toLowerCase(s.charAt(idx))) != 0) {
|
||||
return result;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return length - s.length;
|
||||
}
|
||||
|
||||
public String trim() {
|
||||
|
Loading…
Reference in New Issue
Block a user