コード例 #1
0
ファイル: Desugarer.cs プロジェクト: trtz/retail-ui
        public static Tuple <int, Comparator[]> HyphenRange(string spec)
        {
            string pattern = String.Format(@"^\s*({0}+)\s+\-\s+({0}+)\s*", versionChars);

            var regex = new Regex(pattern);
            var match = regex.Match(spec);

            if (!match.Success)
            {
                return(null);
            }

            PartialVersion minPartialVersion = null;
            PartialVersion maxPartialVersion = null;

            // Parse versions from lower and upper ranges, which might
            // be partial versions.
            try
            {
                minPartialVersion = new PartialVersion(match.Groups[1].Value);
                maxPartialVersion = new PartialVersion(match.Groups[2].Value);
            }
            catch (ArgumentException)
            {
                return(null);
            }

            // Lower range has any non-supplied values replaced with zero
            var minVersion = minPartialVersion.ToZeroVersion();

            Comparator.Operator maxOperator = maxPartialVersion.IsFull()
                                                  ? Comparator.Operator.LessThanOrEqual : Comparator.Operator.LessThan;

            Version maxVersion = null;

            // Partial upper range means supplied version values can't change
            if (!maxPartialVersion.Major.HasValue)
            {
                // eg. upper range = "*", then maxVersion remains null
                // and there's only a minimum
            }
            else if (!maxPartialVersion.Minor.HasValue)
            {
                maxVersion = new Version(maxPartialVersion.Major.Value + 1, 0, 0);
            }
            else if (!maxPartialVersion.Patch.HasValue)
            {
                maxVersion = new Version(maxPartialVersion.Major.Value, maxPartialVersion.Minor.Value + 1, 0);
            }
            else
            {
                // Fully specified max version
                maxVersion = maxPartialVersion.ToZeroVersion();
            }
            return(Tuple.Create(
                       match.Length,
                       minMaxComparators(minVersion, maxVersion, maxOperator)));
        }
コード例 #2
0
ファイル: Desugarer.cs プロジェクト: trtz/retail-ui
        private static Comparator[] minMaxComparators(Version minVersion, Version maxVersion,
                                                      Comparator.Operator maxOperator = Comparator.Operator.LessThan)
        {
            var minComparator = new Comparator(
                Comparator.Operator.GreaterThanOrEqual,
                minVersion);

            if (maxVersion == null)
            {
                return(new[] { minComparator });
            }
            else
            {
                var maxComparator = new Comparator(
                    maxOperator, maxVersion);
                return(new[] { minComparator, maxComparator });
            }
        }