Пример #1
0
        /// <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));
        }
Пример #2
0
        /// <summary>
        /// Attempts to apply one or more modifications, described by the given string.
        /// </summary>
        static public bool TryModify(this IVariantResolver inResolver, object inContext, StringSlice inModifyData, IMethodCache inInvoker = null)
        {
            if (inModifyData.IsWhitespace)
            {
                return(true);
            }

            StringSlice.ISplitter splitter = QuoteAwareSplitter ?? (QuoteAwareSplitter = new StringUtils.ArgsList.Splitter(false));
            bool bSuccess = true;
            VariantModification mod;

            foreach (var group in inModifyData.EnumeratedSplit(splitter, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!VariantModification.TryParse(group, out mod) || !mod.Execute(inResolver, inContext, inInvoker))
                {
                    bSuccess = false;
                }
            }

            return(bSuccess);
        }