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

claude pushed a commit to branch claudenw/updateCasedString
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git

commit 502d4e8729e6e337db8973a342218dc3656e2bbf
Author: Claude Warren <[email protected]>
AuthorDate: Sun Mar 8 09:06:17 2026 +0000

    Switched to cased string preserving the parts from the parsing
---
 .../java/org/apache/rat/utils/CasedString.java     | 63 +++++++++++++++-------
 1 file changed, 44 insertions(+), 19 deletions(-)

diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java 
b/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java
index 79b29d10..df7fcbad 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java
@@ -19,6 +19,7 @@
 package org.apache.rat.utils;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
 import java.util.function.Function;
@@ -32,32 +33,34 @@ import org.apache.commons.text.WordUtils;
  */
 public class CasedString {
     /** the string of the cased format. */
-    private final String string;
+    private final String[] parts;
     /** the case of the string. */
     private final StringCase stringCase;
 
     /**
-     * A method to join camel string fragments together.
+     * A method to join pascal string fragments together.
      */
-    private static final Function<String[], String> CAMEL_JOINER = a -> {
-        StringBuilder sb = new StringBuilder(a[0].toLowerCase(Locale.ROOT));
-
-        for (int i = 1; i < a.length; i++) {
-            sb.append(WordUtils.capitalize(a[i].toLowerCase(Locale.ROOT)));
-        }
+    private static final Function<String[], String> PASCAL_JOINER = strings -> 
{
+        StringBuilder sb = new StringBuilder();
+        Arrays.stream(strings).forEach(token -> 
sb.append(WordUtils.capitalize(token.toLowerCase(Locale.ROOT))));
         return sb.toString();
     };
 
+
     /**
      * An enumeration of supported string cases.  These cases tag strings as 
having a specific format.
      */
     public enum StringCase {
         /**
          * Camel case tags strings like 'CamelCase' or 'camelCase'. This 
conversion forces the first character to
-         * lower case. If specific capitalization rules are required use 
{@link WordUtils#capitalize(String)} to set the first
-         * character of the string.
+         * lower case. If the first character is desired to be upper case use 
PASCAL case instead.
          */
-        CAMEL(Character::isUpperCase, true, CAMEL_JOINER),
+        CAMEL(Character::isUpperCase, true, 
PASCAL_JOINER.andThen(WordUtils::uncapitalize)),
+        /**
+         * Camel case tags strings like 'PascalCase' or 'pascalCase'. This 
conversion forces the first character to
+         * upper case. If the first character is desired to be lower case use 
CAMEL case instead.
+         */
+        PASCAL(Character::isUpperCase, true, PASCAL_JOINER),
         /**
          * Snake case tags strings like 'Snake_Case'.  This conversion does 
not change the capitalization of any characters
          * in the string.  If specific capitalization is required use {@link 
String#toUpperCase()}, {@link String#toLowerCase()},
@@ -83,7 +86,15 @@ public class CasedString {
          * in the string.  If specific capitalization is required use {@link 
String#toUpperCase()}, {@link String#toLowerCase()},
          *          * or the commons-text methods {@link 
WordUtils#capitalize(String)}, or {@link WordUtils#uncapitalize(String)} as 
required.
          */
-        DOT(c -> c == '.', false, a -> String.join(".", a));
+        DOT(c -> c == '.', false, a -> String.join(".", a)),
+
+        /**
+         * Slash case tags phrases of words like 'phrase.case'. This 
conversion does not change the capitalization of any characters
+         * in the string.  If specific capitalization is required use {@link 
String#toUpperCase()}, {@link String#toLowerCase()},
+         *          * or the commons-text methods {@link 
WordUtils#capitalize(String)}, or {@link WordUtils#uncapitalize(String)} as 
required.
+         */
+        SLASH(c -> c == '/', false, a -> String.join("/", a));
+
 
         /** The segment value for a null string */
         private static final String[] NULL_SEGMENT = new String[0];
@@ -158,17 +169,34 @@ public class CasedString {
      * @param string The string.
      */
     public CasedString(final StringCase stringCase, final String string) {
-        this.string = string == null ? null : 
stringCase.assemble(stringCase.getSegments(string.trim()));
+        this.parts = string == null ? StringCase.NULL_SEGMENT : 
stringCase.getSegments(string.trim());
+        this.stringCase = stringCase;
+    }
+
+    /**
+     * A representation of a cased string and the identified case of that 
string.
+     * @param stringCase The {@code StringCase} that the {@code string} 
argument is in.
+     * @param parts The string parts.
+     */
+    public CasedString(final StringCase stringCase, final String[] parts) {
+        this.parts = parts;
         this.stringCase = stringCase;
     }
 
+    public CasedString as(final StringCase stringCase) {
+        if (stringCase == this.stringCase) {
+            return this;
+        }
+        return new CasedString(stringCase, Arrays.copyOf(this.parts, 
this.parts.length));
+    }
+
     /**
      * Returns an array of each of the segments in this CasedString.  Segments 
are defined as the strings between
      * the separators in the CasedString.  For the CAMEL case the segments are 
determined by the presence of a capital letter.
      * @return the array of Strings that are segments of the cased string.
      */
     public String[] getSegments() {
-        return stringCase.getSegments(string);
+        return parts;
     }
 
     /**
@@ -178,10 +206,7 @@ public class CasedString {
      * @return the String current string represented in the new format.
      */
     public String toCase(final StringCase stringCase) {
-        if (stringCase == this.stringCase) {
-            return string;
-        }
-        return string == null ? null : stringCase.joiner.apply(getSegments());
+        return parts == StringCase.NULL_SEGMENT ? null : 
stringCase.joiner.apply(getSegments());
     }
 
     /**
@@ -190,6 +215,6 @@ public class CasedString {
      */
     @Override
     public String toString() {
-        return string;
+        return toCase(stringCase);
     }
 }

Reply via email to