Пример #1
0
        private static (object value, string error) Evaluator(Expression expression, IMemory state, Options options)
        {
            object result = -1;

            var(args, error) = FunctionUtils.EvaluateChildren(expression, state, options);
            if (error == null)
            {
                if (args[0] is string || args[0] == null)
                {
                    if (args[1] is string || args[1] == null)
                    {
                        result = FunctionUtils.ParseStringOrNull(args[0]).IndexOf(FunctionUtils.ParseStringOrNull(args[1]));
                    }
                    else
                    {
                        error = $"Can only look for indexof string in {expression}";
                    }
                }
                else if (FunctionUtils.TryParseList(args[0], out IList list))
                {
                    result = FunctionUtils.ResolveListValue(list).IndexOf(args[1]);
                }
                else
                {
                    error = $"{expression} works only on string or list.";
                }
            }

            return(result, error);
        }
Пример #2
0
        private static EvaluateExpressionDelegate Evaluator()
        {
            return(FunctionUtils.Apply(
                       args =>
            {
                var inputStr = string.Empty;
                var seperator = string.Empty;
                if (args.Count == 1)
                {
                    inputStr = FunctionUtils.ParseStringOrNull(args[0]);
                }
                else
                {
                    inputStr = FunctionUtils.ParseStringOrNull(args[0]);
                    seperator = FunctionUtils.ParseStringOrNull(args[1]);
                }

                if (string.IsNullOrEmpty(seperator))
                {
                    return inputStr.Select(c => c.ToString()).ToArray();
                }

                return inputStr.Split(new string[] { seperator }, 0);
            }, FunctionUtils.VerifyStringOrNull));
        }
 private static EvaluateExpressionDelegate Evaluator()
 {
     return(FunctionUtils.Apply(
                args =>
     {
         var rawStr = FunctionUtils.ParseStringOrNull(args[0]);
         var seekStr = FunctionUtils.ParseStringOrNull(args[1]);
         return rawStr.EndsWith(seekStr, StringComparison.Ordinal);
     }, FunctionUtils.VerifyStringOrNull));
 }
Пример #4
0
 private static EvaluateExpressionDelegate Evaluator()
 {
     return(FunctionUtils.Apply(
                args =>
     {
         string rawStr = FunctionUtils.ParseStringOrNull(args[0]);
         string seekStr = FunctionUtils.ParseStringOrNull(args[1]);
         return rawStr.StartsWith(seekStr);
     }, FunctionUtils.VerifyStringOrNull));
 }
Пример #5
0
        private static EvaluateExpressionDelegate Evaluator()
        {
            return(FunctionUtils.ApplyWithError(
                       args =>
            {
                string error = null;
                string result = null;
                string inputStr = FunctionUtils.ParseStringOrNull(args[0]);
                string oldStr = FunctionUtils.ParseStringOrNull(args[1]);
                if (oldStr.Length == 0)
                {
                    error = $"{args[1]} the oldValue in replace function should be a string with at least length 1.";
                }

                string newStr = FunctionUtils.ParseStringOrNull(args[2]);
                if (error == null)
                {
                    result = inputStr.Replace(oldStr, newStr);
                }

                return (result, error);
            }, FunctionUtils.VerifyStringOrNull));
        }