String (Locale loc) { // First, see how many characters we have to grow by, as well as if the // current string is already upper case. boolean turkish = "tr".equals(loc.getLanguage()); int expand = 0; boolean unchanged = true; int i = count; int x = i + offset; while (--i >= 0) { char ch = value[--x]; expand += upperCaseExpansion(ch); unchanged = (unchanged && expand == 0 && ! (turkish && ch == '\u0069') && ch == Character.toUpperCase(ch)); } if (unchanged) return this; // Now we perform the conversion. i = count; if (expand == 0) { char[] newStr = (char[]) value.clone(); while (--i >= 0) { char ch = value[x]; // Hardcoded special case. newStr[x++] = (turkish && ch == '\u0069') ? '\u0130' : Character.toUpperCase(ch); } // Package constructor avoids an array copy. return new String(newStr, offset, count, true); } // Expansion is necessary. char[] newStr = new char[count + expand]; int j = 0; while (--i >= 0) { char ch = value[x++]; // Hardcoded special case. if (turkish && ch == '\u0069') { newStr[j++] = '\u0130'; continue; } expand = upperCaseExpansion(ch); if (expand > 0) { int index = upperCaseIndex(ch); while (expand-- >= 0) newStr[j++] = upperExpand[index++]; } else newStr[j++] = Character.toUpperCase(ch); } // Package constructor avoids an array copy. return new String(newStr, 0, newStr.length, true); }