public static bool TryParse(string versionString, out SemVersion?result) { try { result = SemVersionParser.Parse(versionString); return(true); } catch (Exception) { result = null; return(false); } }
private ExpressionParsedData ParseExpression(string expression) { ExpressionParsedData expressionParsedData = new ExpressionParsedData(); if (expression.Length == 0) { return(expressionParsedData); } bool hasSeperator = Contains(expression, ','); char leftSymbol = default(char); char rightSymbol = default(char); int begin = 0; int end = expression.Length - 1; if (!IsCharDigit(expression[0])) { leftSymbol = expression[0]; if (!Contains(k_LeftValidSymbols, leftSymbol)) { throw new ExpressionNotValidException($"Invalid character {leftSymbol}", expression); } begin++; } var lastChar = expression[end]; if (!IsCharDigit(lastChar) && !IsCharLetter(lastChar)) { rightSymbol = lastChar; if (!Contains(k_RightValidSymbols, rightSymbol)) { throw new ExpressionNotValidException($"Invalid character {rightSymbol}", expression); } end--; } if (leftSymbol != default(char) && rightSymbol == default(char) || leftSymbol == default(char) && rightSymbol != default(char)) { throw new ExpressionNotValidException("Incomplete expression, missing symbol in start or end", expression); } int nextSemVer; string leftSemVerString = PopSemanticVersion(expression, begin, end, out nextSemVer); var hasLeftSemVer = !string.IsNullOrEmpty(leftSemVerString); if (hasLeftSemVer) { expressionParsedData.leftSemVersion = SemVersionParser.Parse(leftSemVerString); } int notNeeded; string rightSemVerString = PopSemanticVersion(expression, nextSemVer, end, out notNeeded); var hasRightSemVer = !string.IsNullOrEmpty(rightSemVerString); if (hasRightSemVer) { expressionParsedData.rightSemVersion = SemVersionParser.Parse(rightSemVerString); } expressionParsedData.GenerateExpressionTypeKey = new ExpressionTypeKey(leftSymbol: leftSymbol, rightSymbol: rightSymbol, hasSeparator: hasSeperator, hasLeftSemVer: hasLeftSemVer, hasRightSemVer: hasRightSemVer); return(expressionParsedData); }
public SemVersion Parse(string version, bool strict = false) { return(SemVersionParser.Parse(version, strict)); }