/// <summary> /// Attempts to parse a modification. /// </summary> static public bool TryParse(StringSlice inData, out VariantModification outModification) { inData = inData.Trim(); VariantModifyOperator op = default(VariantModifyOperator); int operatorIdx = -1; int operatorLength = 0; VariantUtils.TryFindOperator(inData, '=', VariantModifyOperator.Set, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, '+', VariantModifyOperator.Add, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, '-', VariantModifyOperator.Subtract, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, '*', VariantModifyOperator.Multiply, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, '/', VariantModifyOperator.Divide, ref operatorIdx, ref op, ref operatorLength); if (operatorIdx < 0) { outModification = default(VariantModification); return(false); } outModification.Operator = op; StringSlice key = inData.Substring(0, operatorIdx); StringSlice operand = inData.Substring(operatorIdx + 1); if (!TableKeyPair.TryParse(key, out outModification.VariableKey)) { outModification = default(VariantModification); return(false); } return(VariantOperand.TryParse(operand, out outModification.Operand)); }
/// <summary> /// Attempts to parse a comparison. /// </summary> static public bool TryParse(StringSlice inData, out VariantComparison outComparison) { inData = inData.Trim(); VariantCompareOperator op = VariantCompareOperator.True; int operatorIdx = -1; int operatorLength = 0; VariantUtils.TryFindOperator(inData, EqualsOperator, VariantCompareOperator.EqualTo, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, NotEqualOperator, VariantCompareOperator.NotEqualTo, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, GreaterThanOrEqualToOperator, VariantCompareOperator.GreaterThanOrEqualTo, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, LessThanOrEqualToOperator, VariantCompareOperator.LessThanOrEqualTo, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, GreaterThanOperator, VariantCompareOperator.GreaterThan, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, LessThanOperator, VariantCompareOperator.LessThan, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, NotOperator, VariantCompareOperator.False, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, ShortEqualsOperator, VariantCompareOperator.EqualTo, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, ExistsOperator, VariantCompareOperator.Exists, ref operatorIdx, ref op, ref operatorLength); VariantUtils.TryFindOperator(inData, DoesNotExistOperator, VariantCompareOperator.DoesNotExist, ref operatorIdx, ref op, ref operatorLength); if (operatorIdx < 0) { op = VariantCompareOperator.True; } outComparison.Operator = op; StringSlice idSlice = StringSlice.Empty; StringSlice operandSlice = StringSlice.Empty; bool bRequiresOperand = true; switch (op) { case VariantCompareOperator.False: { idSlice = inData.Substring(1).TrimStart(); bRequiresOperand = false; break; } case VariantCompareOperator.True: { idSlice = inData; bRequiresOperand = false; break; } case VariantCompareOperator.Exists: { idSlice = inData.Substring(0, operatorIdx).TrimEnd(); bRequiresOperand = false; break; } case VariantCompareOperator.DoesNotExist: { idSlice = inData.Substring(0, operatorIdx).TrimEnd(); bRequiresOperand = false; break; } default: { idSlice = inData.Substring(0, operatorIdx).TrimEnd(); operandSlice = inData.Substring(operatorIdx + operatorLength).TrimStart(); break; } } if (!VariantOperand.TryParse(idSlice, out outComparison.Left)) { outComparison = default(VariantComparison); return(false); } if (!bRequiresOperand) { outComparison.Right = default(VariantOperand); return(true); } return(VariantOperand.TryParse(operandSlice, out outComparison.Right)); }