public static VersionRange parse(String versionRangeString) throws NugetFormatException {
if (versionRangeString == null || versionRangeString.isEmpty()) {
return new VersionRange();
}
if (Version.isValidVersionString(versionRangeString)) {
Version version = Version.parse(versionRangeString);
return new VersionRange(version, BorderType.INCLUDE, null, null);
}
Pattern fixedVersionPattern = Pattern.compile("^" + FIXED_VERSION_RANGE_PATTERN + "$");
Matcher fixedVersionMatcher = fixedVersionPattern.matcher(versionRangeString);
if (fixedVersionMatcher.matches()) {
Version version = Version.parse(fixedVersionMatcher.group(1));
return new VersionRange(version, BorderType.INCLUDE, version, BorderType.INCLUDE);
}
Pattern pattern = Pattern.compile("^" + FULL_VERSION_RANGE_PATTERN + "$");
Matcher matcher = pattern.matcher(versionRangeString);
if (matcher.matches()) {
Version lowVersion = null;
BorderType lowBorder = null;
String lowVersionString = matcher.group("left");
if (!lowVersionString.isEmpty()) {
lowVersion = Version.parse(lowVersionString);
lowBorder = BorderType.getBorderType(matcher.group("leftBorder"));
}
Version topVersion = null;
BorderType topBorder = null;
String topVersionString = matcher.group("right");
if (!topVersionString.isEmpty()) {
topVersion = Version.parse(topVersionString);
topBorder = BorderType.getBorderType(matcher.group("rightBorder"));