Skip to content

Commit

Permalink
Update DottedVersion to support multiple letters
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Feb 20, 2019
1 parent 7fe8d34 commit 4bb3618
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* {@code 5.0.1beta2}. Components must start with a non-negative integer and at least one component
* must be present.
*
* <p>Specifically, the format of a component is {@code \d+([a-z]+\d*)?}.
* <p>Specifically, the format of a component is {@code \d+([a-z0-9]*?)?(\d+)?}.
*
* <p>Dotted versions are ordered using natural integer sorting on components in order from first to
* last where any missing element is considered to have the value 0 if they don't contain any
Expand Down Expand Up @@ -122,9 +122,10 @@ public static Option option(DottedVersion version) {
return version == null ? null : new Option(version);
}
private static final Splitter DOT_SPLITTER = Splitter.on('.');
private static final Pattern COMPONENT_PATTERN = Pattern.compile("(\\d+)(?:([a-z]+)(\\d*))?");
private static final Pattern COMPONENT_PATTERN =
Pattern.compile("(\\d+)([a-z0-9]*?)?(\\d+)?", Pattern.CASE_INSENSITIVE);
private static final String ILLEGAL_VERSION =
"Dotted version components must all be of the form \\d+([a-z]+\\d*)? but got %s";
"Dotted version components must all be of the form \\d+([a-z0-9]*?)?(\\d+)? but got %s";
private static final String NO_ALPHA_SEQUENCE = null;
private static final Component ZERO_COMPONENT = new Component(0, NO_ALPHA_SEQUENCE, 0, "0");

Expand Down Expand Up @@ -165,7 +166,7 @@ private static Component toComponent(String component, String version) {
int secondNumber = 0;
firstNumber = parseNumber(parsedComponent, 1, version);

if (parsedComponent.group(2) != null) {
if (!Strings.isNullOrEmpty(parsedComponent.group(2))) {
alphaSequence = parsedComponent.group(2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void testCompareTo() throws Exception {
.addEqualityGroup(DottedVersion.fromString("1.2beta12.1"))
.addEqualityGroup(DottedVersion.fromString("1.2.0"), DottedVersion.fromString("1.2"))
.addEqualityGroup(DottedVersion.fromString("1.20"))
.addEqualityGroup(DottedVersion.fromString("10.2.0.10P99q"))
.testCompare();
}

Expand All @@ -52,6 +53,7 @@ public void testEquals() throws Exception {
.addEqualityGroup(DottedVersion.fromString("0.1"), DottedVersion.fromString("0.01"))
.addEqualityGroup(DottedVersion.fromString("0.2"), DottedVersion.fromString("0.2.0"))
.addEqualityGroup(DottedVersion.fromString("1.2xy2"), DottedVersion.fromString("1.2xy2"))
.addEqualityGroup(DottedVersion.fromString("10.2.0.10P99q"), DottedVersion.fromString("10.2.0.10P99q0"))
.addEqualityGroup(
DottedVersion.fromString("1.2x"),
DottedVersion.fromString("1.2x0"),
Expand Down

0 comments on commit 4bb3618

Please sign in to comment.