gnodet commented on code in PR #2071:
URL: https://github.com/apache/maven/pull/2071#discussion_r1935325435


##########
compat/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java:
##########
@@ -687,7 +700,8 @@ public final void parseVersion(String version) {
                     stack.push(list);
                 }
                 isCombination = false;
-            } else if (Character.isDigit(c)) {
+                // TODO we might not want to use isDigit here; just check for 
ASCII digits only
+            } else if (c >= '0' && c <= '9') {

Review Comment:
   Something like the following maybe ?
   ```java
   @SuppressWarnings("checkstyle:innerassignment")
   public final void parseVersion(String version) {
       this.value = version;
   
       items = new ListItem();
   
       version = version.toLowerCase(Locale.ENGLISH);
   
       ListItem list = items;
   
       Deque<Item> stack = new ArrayDeque<>();
       stack.push(list);
   
       boolean isDigit = false;
   
       boolean isCombination = false;
   
       int startIndex = 0;
   
       StringBuilder normalizedBuffer = new StringBuilder();
   
       for (int i = 0; i < version.length(); i++) {
           char character = version.charAt(i);
           int c = character;
   
           // Handle high surrogate
           if (Character.isHighSurrogate(character)) {
               try {
                   char low = version.charAt(i + 1);
                   char[] both = {character, low};
                   c = Character.codePointAt(both, 0);
                   i++;
               } catch (IndexOutOfBoundsException ex) {
                   // Treat high surrogate without low surrogate as a regular 
character
               }
           }
   
           // Normalize the Unicode digits (including supplemental plane 
characters) using Character.digit()
           if (Character.isDigit(c)) {
               // Normalize Unicode digits to ASCII digits
               int normalizedDigit = Character.digit(c, 10);
               if (normalizedDigit != -1) {
                   c = normalizedDigit + '0'; // Convert digit to its ASCII 
equivalent
               }
           }
   
           // Build the normalized substring on the fly
           if (c == '.' || c == '-' || i == version.length() - 1) {
               // If we've reached a separator or the end of the string, 
process the current segment
               if (i == startIndex && c != '-') {
                   list.add(IntItem.ZERO);  // Handle empty sections
               } else {
                   // Add the current segment to the list after normalizing it
                   list.add(parseItem(isCombination, isDigit, 
normalizedBuffer.toString()));
               }
               isCombination = false;
               normalizedBuffer.setLength(0);  // Reset the buffer for the next 
segment
               startIndex = i + 1;
   
               // Handle separators
               if (c == '-' && !list.isEmpty()) {
                   list.add(list = new ListItem());
                   stack.push(list);
               }
           } else if (c >= '0' && c <= '9') {
               if (!isDigit && i > startIndex) {
                   // Handle combination of a letter and number, like "X1"
                   isCombination = true;
                   if (!list.isEmpty()) {
                       list.add(list = new ListItem());
                       stack.push(list);
                   }
               }
               isDigit = true;
           } else {
               if (isDigit && i > startIndex) {
                   list.add(parseItem(isCombination, true, 
normalizedBuffer.toString()));
                   normalizedBuffer.setLength(0);  // Reset buffer
                   startIndex = i;
   
                   list.add(list = new ListItem());
                   stack.push(list);
                   isCombination = false;
               }
   
               isDigit = false;
           }
   
           // Append the current character to the normalized buffer
           normalizedBuffer.append((char) c);
       }
   
       if (version.length() > startIndex) {
           // Final segment (if any)
           if (!isDigit && !list.isEmpty()) {
               list.add(list = new ListItem());
               stack.push(list);
           }
   
           list.add(parseItem(isCombination, isDigit, 
normalizedBuffer.toString()));
       }
   
       while (!stack.isEmpty()) {
           list = (ListItem) stack.pop();
           list.normalize();
       }
   }
   ```
    



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to