This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 7d56fe109519455f0a2ff87b9e94d3914170c592
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Apr 15 15:51:34 2025 -0400

    Reimplement StringUtils.uncapitalize(String) to use
    java.lang.CharSequence.codePoints()
    
    Fix code comment
---
 src/changes/changes.xml                                 |  1 +
 src/main/java/org/apache/commons/lang3/StringUtils.java | 16 ++++------------
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e9aaac334..93d85ca57 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -86,6 +86,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action issue="LANG-1768" type="fix" dev="ggregory" due-to="Wang Hailong, 
Gary Gregory">MutableLong and friends should provide better parsing exceptions 
Javadocs.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary 
Gregory">Reimplement StringUtils.toCodePoints(CharSequence) to use 
java.lang.CharSequence.codePoints().</action>
     <action                   type="fix" dev="ggregory" due-to="Gary 
Gregory">Reimplement StringUtils.capitalize(String) to use 
java.lang.CharSequence.codePoints().</action>
+    <action                   type="fix" dev="ggregory" due-to="Gary 
Gregory">Reimplement StringUtils.uncapitalize(String) to use 
java.lang.CharSequence.codePoints().</action>
     <!-- ADD -->
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add Strings and refactor StringUtils.</action>
     <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>
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java 
b/src/main/java/org/apache/commons/lang3/StringUtils.java
index b509fdf68..5ddc3bbde 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -8965,23 +8965,15 @@ public static String uncapitalize(final String str) {
         if (strLen == 0) {
             return str;
         }
-
         final int firstCodePoint = str.codePointAt(0);
         final int newCodePoint = Character.toLowerCase(firstCodePoint);
         if (firstCodePoint == newCodePoint) {
-            // already capitalized
+            // already uncapitalized
             return str;
         }
-
-        final int[] newCodePoints = new int[strLen]; // cannot be longer than 
the char array
-        int outOffset = 0;
-        newCodePoints[outOffset++] = newCodePoint; // copy the first code point
-        for (int inOffset = Character.charCount(firstCodePoint); inOffset < 
strLen; ) {
-            final int codePoint = str.codePointAt(inOffset);
-            newCodePoints[outOffset++] = codePoint; // copy the remaining ones
-            inOffset += Character.charCount(codePoint);
-         }
-        return new String(newCodePoints, 0, outOffset);
+        final int[] newCodePoints = str.codePoints().toArray();
+        newCodePoints[0] = newCodePoint; // copy the first code point
+        return new String(newCodePoints, 0, newCodePoints.length);
     }
 
     /**

Reply via email to