// Allows patch-level changes if a minor version is specified
// on the comparator. Allows minor-level changes if not.
public static Tuple<int, Comparator[]> TildeRange(string spec)
{
string pattern = String.Format(@"^\s*~\s*({0}+)\s*", versionChars);
var regex = new Regex(pattern);
var match = regex.Match(spec);
if (!match.Success)
{
return null;
}
Version minVersion = null;
Version maxVersion = null;
var version = new PartialVersion(match.Groups[1].Value);
if (version.Minor.HasValue)
{
// Doesn't matter whether patch version is null or not,
// the logic is the same, min patch version will be zero if null.
minVersion = version.ToZeroVersion();
maxVersion = new Version(version.Major.Value, version.Minor.Value + 1, 0);
}
else
{
minVersion = version.ToZeroVersion();
maxVersion = new Version(version.Major.Value + 1, 0, 0);
}
return Tuple.Create(
match.Length,
minMaxComparators(minVersion, maxVersion));
}