You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/04/15 19:55:33 UTC

(commons-lang) branch master updated (5f1200c35 -> 7d56fe109)

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

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


    from 5f1200c35 Reimplement StringUtils.toCodePoints(CharSequence) to use java.lang.CharSequence.codePoints()
     new 76d30201f Reimplement StringUtils.capitalize(String) to use java.lang.CharSequence.codePoints()
     new 7d56fe109 Reimplement StringUtils.uncapitalize(String) to use java.lang.CharSequence.codePoints()

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  2 ++
 .../java/org/apache/commons/lang3/StringUtils.java | 33 ++++++----------------
 2 files changed, 10 insertions(+), 25 deletions(-)


(commons-lang) 01/02: Reimplement StringUtils.capitalize(String) to use java.lang.CharSequence.codePoints()

Posted by gg...@apache.org.
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 76d30201faf8f5c116c3130b880d8b494a5bfc8f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Apr 15 15:43:54 2025 -0400

    Reimplement StringUtils.capitalize(String) to use
    java.lang.CharSequence.codePoints()
---
 src/changes/changes.xml                                 |  1 +
 src/main/java/org/apache/commons/lang3/StringUtils.java | 17 ++++-------------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8cd9319fe..e9aaac334 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -85,6 +85,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">Several hash collisions in Fraction class.</action>
     <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>
     <!-- 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 207fb025b..b509fdf68 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -517,27 +517,18 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
      * @since 2.0
      */
     public static String capitalize(final String str) {
-        final int strLen = length(str);
-        if (strLen == 0) {
+        if (isEmpty(str)) {
             return str;
         }
-
         final int firstCodepoint = str.codePointAt(0);
         final int newCodePoint = Character.toTitleCase(firstCodepoint);
         if (firstCodepoint == newCodePoint) {
             // already capitalized
             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);
     }
 
     /**


(commons-lang) 02/02: Reimplement StringUtils.uncapitalize(String) to use java.lang.CharSequence.codePoints()

Posted by gg...@apache.org.
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 <ga...@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);
     }
 
     /**