Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. public String toLowerCase(Locale locale) {
  2. if (locale == null) {
  3. throw new NullPointerException();
  4. }
  5.  
  6. int firstUpper;
  7. final int len = value.length;
  8.  
  9. /* Now check if there are any characters that need to be changed. */
  10. scan: {
  11. for (firstUpper = 0 ; firstUpper < len; ) {
  12. char c = value[firstUpper];
  13. if ((c >= Character.MIN_HIGH_SURROGATE)
  14. && (c <= Character.MAX_HIGH_SURROGATE)) {
  15. int supplChar = codePointAt(firstUpper);
  16. if (supplChar != Character.toLowerCase(supplChar)) {
  17. break scan;
  18. }
  19. firstUpper += Character.charCount(supplChar);
  20. } else {
  21. if (c != Character.toLowerCase(c)) {
  22. break scan;
  23. }
  24. firstUpper++;
  25. }
  26. }
  27. return this;
  28. }
  29.  
  30. char[] result = new char[len];
  31. int resultOffset = 0; /* result may grow, so i+resultOffset
  32. * is the write location in result */
  33.  
  34. /* Just copy the first few lowerCase characters. */
  35. System.arraycopy(value, 0, result, 0, firstUpper);
  36.  
  37. String lang = locale.getLanguage();
  38. boolean localeDependent =
  39. (lang == "tr" || lang == "az" || lang == "lt");
  40. char[] lowerCharArray;
  41. int lowerChar;
  42. int srcChar;
  43. int srcCount;
  44. for (int i = firstUpper; i < len; i += srcCount) {
  45. srcChar = (int)value[i];
  46. if ((char)srcChar >= Character.MIN_HIGH_SURROGATE
  47. && (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
  48. srcChar = codePointAt(i);
  49. srcCount = Character.charCount(srcChar);
  50. } else {
  51. srcCount = 1;
  52. }
  53. if (localeDependent ||
  54. srcChar == '\u03A3' || // GREEK CAPITAL LETTER SIGMA
  55. srcChar == '\u0130') { // LATIN CAPITAL LETTER I WITH DOT ABOVE
  56. lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
  57. } else {
  58. lowerChar = Character.toLowerCase(srcChar);
  59. }
  60. if ((lowerChar == Character.ERROR)
  61. || (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
  62. if (lowerChar == Character.ERROR) {
  63. lowerCharArray =
  64. ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
  65. } else if (srcCount == 2) {
  66. resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
  67. continue;
  68. } else {
  69. lowerCharArray = Character.toChars(lowerChar);
  70. }
  71.  
  72. /* Grow result if needed */
  73. int mapLen = lowerCharArray.length;
  74. if (mapLen > srcCount) {
  75. char[] result2 = new char[result.length + mapLen - srcCount];
  76. System.arraycopy(result, 0, result2, 0, i + resultOffset);
  77. result = result2;
  78. }
  79. for (int x = 0; x < mapLen; ++x) {
  80. result[i + resultOffset + x] = lowerCharArray[x];
  81. }
  82. resultOffset += (mapLen - srcCount);
  83. } else {
  84. result[i + resultOffset] = (char)lowerChar;
  85. }
  86. }
  87. return new String(result, 0, len + resultOffset);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement