Skip to content

Commit 7d56fe1

Browse files
committed
Reimplement StringUtils.uncapitalize(String) to use
java.lang.CharSequence.codePoints() Fix code comment
1 parent 76d3020 commit 7d56fe1

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The <action> type attribute can be add,update,fix,remove.
8686
<action issue="LANG-1768" type="fix" dev="ggregory" due-to="Wang Hailong, Gary Gregory">MutableLong and friends should provide better parsing exceptions Javadocs.</action>
8787
<action type="fix" dev="ggregory" due-to="Gary Gregory">Reimplement StringUtils.toCodePoints(CharSequence) to use java.lang.CharSequence.codePoints().</action>
8888
<action type="fix" dev="ggregory" due-to="Gary Gregory">Reimplement StringUtils.capitalize(String) to use java.lang.CharSequence.codePoints().</action>
89+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Reimplement StringUtils.uncapitalize(String) to use java.lang.CharSequence.codePoints().</action>
8990
<!-- ADD -->
9091
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Strings and refactor StringUtils.</action>
9192
<action issue="LANG-1747" type="add" dev="ggregory" due-to="Oliver B. Fischer, Gary Gregory">Add StopWatch.run([Failable]Runnable) and get([Failable]Supplier).</action>

src/main/java/org/apache/commons/lang3/StringUtils.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8965,23 +8965,15 @@ public static String uncapitalize(final String str) {
89658965
if (strLen == 0) {
89668966
return str;
89678967
}
8968-
89698968
final int firstCodePoint = str.codePointAt(0);
89708969
final int newCodePoint = Character.toLowerCase(firstCodePoint);
89718970
if (firstCodePoint == newCodePoint) {
8972-
// already capitalized
8971+
// already uncapitalized
89738972
return str;
89748973
}
8975-
8976-
final int[] newCodePoints = new int[strLen]; // cannot be longer than the char array
8977-
int outOffset = 0;
8978-
newCodePoints[outOffset++] = newCodePoint; // copy the first code point
8979-
for (int inOffset = Character.charCount(firstCodePoint); inOffset < strLen; ) {
8980-
final int codePoint = str.codePointAt(inOffset);
8981-
newCodePoints[outOffset++] = codePoint; // copy the remaining ones
8982-
inOffset += Character.charCount(codePoint);
8983-
}
8984-
return new String(newCodePoints, 0, outOffset);
8974+
final int[] newCodePoints = str.codePoints().toArray();
8975+
newCodePoints[0] = newCodePoint; // copy the first code point
8976+
return new String(newCodePoints, 0, newCodePoints.length);
89858977
}
89868978

89878979
/**

0 commit comments

Comments
 (0)