mirror of
https://github.com/corda/corda.git
synced 2025-01-16 17:59:46 +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) {
|
public int compareTo(String s) {
|
||||||
if (this == s) return 0;
|
if (this == s) return 0;
|
||||||
|
|
||||||
int d = length - s.length;
|
int idx = 0;
|
||||||
if (d != 0) {
|
int result;
|
||||||
return d;
|
|
||||||
} else {
|
int end = (length < s.length ? length : s.length);
|
||||||
for (int i = 0; i < length; ++i) {
|
|
||||||
d = charAt(i) - s.charAt(i);
|
while (idx < end) {
|
||||||
if (d != 0) {
|
if ((result = charAt(idx) - s.charAt(idx)) != 0) {
|
||||||
return d;
|
return result;
|
||||||
}
|
}
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
return 0;
|
return length - s.length;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareToIgnoreCase(String s) {
|
public int compareToIgnoreCase(String s) {
|
||||||
if (this == s) return 0;
|
if (this == s) return 0;
|
||||||
|
|
||||||
int d = length - s.length;
|
int idx = 0;
|
||||||
if (d != 0) {
|
int result;
|
||||||
return d;
|
|
||||||
} else {
|
int end = (length < s.length ? length : s.length);
|
||||||
for (int i = 0; i < length; ++i) {
|
|
||||||
d = Character.toLowerCase(charAt(i))
|
while (idx < end) {
|
||||||
- Character.toLowerCase(s.charAt(i));
|
if ((result =
|
||||||
if (d != 0) {
|
Character.toLowerCase(charAt(idx)) -
|
||||||
return d;
|
Character.toLowerCase(s.charAt(idx))) != 0) {
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
return 0;
|
return length - s.length;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String trim() {
|
public String trim() {
|
||||||
|
Loading…
Reference in New Issue
Block a user