implement toLowerCase(Locale) in the default case

This commit is contained in:
Zsombor Gegesy
2010-08-15 13:28:29 +02:00
parent 250a77dc13
commit fc2c6d5100

View File

@ -236,19 +236,31 @@ public final class String
} }
public String toLowerCase() { public String toLowerCase() {
char[] b = new char[length]; for (int j = 0; j < length; ++j) {
for (int i = 0; i < length; ++i) { char ch = charAt(j);
b[i] = Character.toLowerCase(charAt(i)); if (Character.toLowerCase(ch) != ch) {
char[] b = new char[length];
for (int i = 0; i < length; ++i) {
b[i] = Character.toLowerCase(charAt(i));
}
return new String(b, 0, length, false);
}
} }
return new String(b, 0, length, false); return this;
} }
public String toUpperCase() { public String toUpperCase() {
char[] b = new char[length]; for (int j = 0; j < length; ++j) {
for (int i = 0; i < length; ++i) { char ch = charAt(j);
b[i] = Character.toUpperCase(charAt(i)); if (Character.toUpperCase(ch) != ch) {
char[] b = new char[length];
for (int i = 0; i < length; ++i) {
b[i] = Character.toUpperCase(charAt(i));
}
return new String(b, 0, length, false);
}
} }
return new String(b, 0, length, false); return this;
} }
public int indexOf(int c) { public int indexOf(int c) {
@ -581,11 +593,19 @@ public final class String
} }
public String toUpperCase(Locale locale) { public String toUpperCase(Locale locale) {
throw new UnsupportedOperationException(); if (locale == Locale.ENGLISH) {
return toUpperCase();
} else {
throw new UnsupportedOperationException("toUpperCase("+locale+')');
}
} }
public String toLowerCase(Locale locale) { public String toLowerCase(Locale locale) {
throw new UnsupportedOperationException(); if (locale == Locale.ENGLISH) {
return toLowerCase();
} else {
throw new UnsupportedOperationException("toLowerCase("+locale+')');
}
} }
public static String format(Locale locale, String format, Object ... args) { public static String format(Locale locale, String format, Object ... args) {