in compat/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java [642:746]
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;
for (int i = 0; i < version.length(); i++) {
char character = version.charAt(i);
int c = character;
if (Character.isHighSurrogate(character)) {
// read the next character as a low surrogate and combine into a single int
try {
char low = version.charAt(i + 1);
char[] both = {character, low};
c = Character.codePointAt(both, 0);
i++;
} catch (IndexOutOfBoundsException ex) {
// high surrogate without low surrogate. Not a lot we can do here except treat it as a regular
// character
}
}
if (c == '.') {
if (i == startIndex) {
list.add(IntItem.ZERO);
} else {
list.add(parseItem(isCombination, isDigit, version.substring(startIndex, i)));
}
isCombination = false;
startIndex = i + 1;
} else if (c == '-') {
if (i == startIndex) {
list.add(IntItem.ZERO);
} else {
// X-1 is going to be treated as X1
if (!isDigit && i != version.length() - 1) {
char c1 = version.charAt(i + 1);
if (Character.isDigit(c1)) {
isCombination = true;
continue;
}
}
list.add(parseItem(isCombination, isDigit, version.substring(startIndex, i)));
}
startIndex = i + 1;
if (!list.isEmpty()) {
list.add(list = new ListItem());
stack.push(list);
}
isCombination = false;
} else if (c >= '0' && c <= '9') { // Check for ASCII digits only
if (!isDigit && i > startIndex) {
// 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, version.substring(startIndex, i)));
startIndex = i;
list.add(list = new ListItem());
stack.push(list);
isCombination = false;
}
isDigit = false;
}
}
if (version.length() > startIndex) {
// 1.0.0.X1 < 1.0.0-X2
// treat .X as -X for any string qualifier X
if (!isDigit && !list.isEmpty()) {
list.add(list = new ListItem());
stack.push(list);
}
list.add(parseItem(isCombination, isDigit, version.substring(startIndex)));
}
while (!stack.isEmpty()) {
list = (ListItem) stack.pop();
list.normalize();
}
}