示例#1
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            if (version == null)
            {
                result.SetFailure(ParseFailureKind.ArgumentNullException);
                return(false);
            }

            string[] array = version.Split(SeparatorsArray);
            int      num   = array.Length;

            if (num < 2 || num > 4)
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }

            if (!TryParseComponent(array[0], "version", ref result, out int parsedComponent))
            {
                return(false);
            }

            if (!TryParseComponent(array[1], "version", ref result, out int parsedComponent2))
            {
                return(false);
            }

            num -= 2;
            if (num > 0)
            {
                if (!TryParseComponent(array[2], "build", ref result, out int parsedComponent3))
                {
                    return(false);
                }

                num--;
                if (num > 0)
                {
                    if (!TryParseComponent(array[3], "revision", ref result, out int parsedComponent4))
                    {
                        return(false);
                    }

                    result.m_parsedVersion = new VersionEx(parsedComponent, parsedComponent2, parsedComponent3, parsedComponent4);
                }
                else
                {
                    result.m_parsedVersion = new VersionEx(parsedComponent, parsedComponent2, parsedComponent3);
                }
            }
            else
            {
                result.m_parsedVersion = new VersionEx(parsedComponent, parsedComponent2);
            }

            return(true);
        }
示例#2
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            int num;
            int num2;

            if (version == null)
            {
                result.SetFailure(ParseFailureKind.ArgumentNullException);
                return(false);
            }
            string[] strArray = version.Split(new char[] { '.' });
            int      length   = strArray.Length;

            if ((length < 2) || (length > 4))
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }
            if (!TryParseComponent(strArray[0], "version", ref result, out num))
            {
                return(false);
            }
            if (!TryParseComponent(strArray[1], "version", ref result, out num2))
            {
                return(false);
            }
            length -= 2;
            if (length > 0)
            {
                int num3;
                if (!TryParseComponent(strArray[2], "build", ref result, out num3))
                {
                    return(false);
                }
                length--;
                if (length > 0)
                {
                    int num4;
                    if (!TryParseComponent(strArray[3], "revision", ref result, out num4))
                    {
                        return(false);
                    }
                    result.m_parsedVersion = new Version(num, num2, num3, num4);
                }
                else
                {
                    result.m_parsedVersion = new Version(num, num2, num3);
                }
            }
            else
            {
                result.m_parsedVersion = new Version(num, num2);
            }
            return(true);
        }
示例#3
0
 private static bool TryParseComponent(string component, string componentName, ref VersionResult result, out int parsedComponent)
 {
     if (!int.TryParse(component, NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedComponent))
     {
         result.SetFailure(ParseFailureKind.FormatException, component);
         return(false);
     }
     if (parsedComponent < 0)
     {
         result.SetFailure(ParseFailureKind.ArgumentOutOfRangeException, componentName);
         return(false);
     }
     return(true);
 }
示例#4
0
        private static bool TryParseComponent(string component, string componentName, ref VersionResult result, out int parsedComponent)
        {
            if (!Int32.TryParse(component, out parsedComponent))
            {
                result.SetFailure(ParseFailureKind.FormatException, component);
                return(false);
            }

            if (parsedComponent < 0)
            {
                result.SetFailure(ParseFailureKind.ArgumentOutOfRangeException, componentName);
                return(false);
            }

            return(true);
        }
示例#5
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            var dashIndex = version.IndexOf('-');

            // Empty label?
            if (dashIndex == version.Length - 1)
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }

            var versionSansLabel = (dashIndex < 0) ? version : version.Substring(0, dashIndex);

            string[] parsedComponents = versionSansLabel.Split(Utils.Separators.Dot);
            if (parsedComponents.Length != 3)
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }

            int major, minor, patch;

            if (!TryParseComponent(parsedComponents[0], "major", ref result, out major))
            {
                return(false);
            }

            if (!TryParseComponent(parsedComponents[1], "minor", ref result, out minor))
            {
                return(false);
            }

            if (!TryParseComponent(parsedComponents[2], "patch", ref result, out patch))
            {
                return(false);
            }

            result._parsedVersion = dashIndex < 0
                ? new SemanticVersion(major, minor, patch)
                : new SemanticVersion(major, minor, patch, version.Substring(dashIndex + 1));
            return(true);
        }
示例#6
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            int major, minor, build, revision;

            if ((Object)version == null)
            {
                result.SetFailure(ParseFailureKind.ArgumentNullException);
                return(false);
            }

            String[] parsedComponents       = version.Split(SeparatorsArray);
            int      parsedComponentsLength = parsedComponents.Length;

            if ((parsedComponentsLength < 2) || (parsedComponentsLength > 4))
            {
                result.SetFailure(ParseFailureKind.ArgumentException);
                return(false);
            }

            if (!TryParseComponent(parsedComponents[0], "version", ref result, out major))
            {
                return(false);
            }

            if (!TryParseComponent(parsedComponents[1], "version", ref result, out minor))
            {
                return(false);
            }

            parsedComponentsLength -= 2;

            if (parsedComponentsLength > 0)
            {
                if (!TryParseComponent(parsedComponents[2], "build", ref result, out build))
                {
                    return(false);
                }

                parsedComponentsLength--;

                if (parsedComponentsLength > 0)
                {
                    if (!TryParseComponent(parsedComponents[3], "revision", ref result, out revision))
                    {
                        return(false);
                    }
                    else
                    {
                        result.m_parsedVersion = new Version(major, minor, build, revision);
                    }
                }
                else
                {
                    result.m_parsedVersion = new Version(major, minor, build);
                }
            }
            else
            {
                result.m_parsedVersion = new Version(major, minor);
            }

            return(true);
        }
示例#7
0
        private static bool TryParseVersion(string version, ref VersionResult result)
        {
            if (version.EndsWith('-') || version.EndsWith('+') || version.EndsWith('.'))
            {
                result.SetFailure(ParseFailureKind.FormatException);
                return(false);
            }

            string versionSansLabel = null;
            var    major            = 0;
            var    minor            = 0;
            var    patch            = 0;
            string preLabel         = null;
            string buildLabel       = null;

            // We parse the SymVer 'version' string 'major.minor.patch-PreReleaseLabel+BuildLabel'.
            var dashIndex = version.IndexOf('-');
            var plusIndex = version.IndexOf('+');

            if (dashIndex > plusIndex)
            {
                // 'PreReleaseLabel' can contains dashes.
                if (plusIndex == -1)
                {
                    // No buildLabel: buildLabel == null
                    // Format is 'major.minor.patch-PreReleaseLabel'
                    preLabel         = version.Substring(dashIndex + 1);
                    versionSansLabel = version.Substring(0, dashIndex);
                }
                else
                {
                    // No PreReleaseLabel: preLabel == null
                    // Format is 'major.minor.patch+BuildLabel'
                    buildLabel       = version.Substring(plusIndex + 1);
                    versionSansLabel = version.Substring(0, plusIndex);
                    dashIndex        = -1;
                }
            }
            else
            {
                if (dashIndex == -1)
                {
                    // Here dashIndex == plusIndex == -1
                    // No preLabel - preLabel == null;
                    // No buildLabel - buildLabel == null;
                    // Format is 'major.minor.patch'
                    versionSansLabel = version;
                }
                else
                {
                    // Format is 'major.minor.patch-PreReleaseLabel+BuildLabel'
                    preLabel         = version.Substring(dashIndex + 1, plusIndex - dashIndex - 1);
                    buildLabel       = version.Substring(plusIndex + 1);
                    versionSansLabel = version.Substring(0, dashIndex);
                }
            }

            if ((dashIndex != -1 && String.IsNullOrEmpty(preLabel)) ||
                (plusIndex != -1 && String.IsNullOrEmpty(buildLabel)) ||
                String.IsNullOrEmpty(versionSansLabel))
            {
                // We have dash and no preReleaseLabel  or
                // we have plus and no buildLabel or
                // we have no main version part (versionSansLabel==null)
                result.SetFailure(ParseFailureKind.FormatException);
                return(false);
            }

            var match = Regex.Match(versionSansLabel, VersionSansRegEx);

            if (!match.Success)
            {
                result.SetFailure(ParseFailureKind.FormatException);
                return(false);
            }

            if (!int.TryParse(match.Groups["major"].Value, out major))
            {
                result.SetFailure(ParseFailureKind.FormatException);
                return(false);
            }

            if (match.Groups["minor"].Success && !int.TryParse(match.Groups["minor"].Value, out minor))
            {
                result.SetFailure(ParseFailureKind.FormatException);
                return(false);
            }

            if (match.Groups["patch"].Success && !int.TryParse(match.Groups["patch"].Value, out patch))
            {
                result.SetFailure(ParseFailureKind.FormatException);
                return(false);
            }

            if (preLabel != null && !Regex.IsMatch(preLabel, LabelUnitRegEx) ||
                (buildLabel != null && !Regex.IsMatch(buildLabel, LabelUnitRegEx)))
            {
                result.SetFailure(ParseFailureKind.FormatException);
                return(false);
            }

            result._parsedVersion = new SemanticVersion(major, minor, patch, preLabel, buildLabel);
            return(true);
        }