Exemple #1
0
        public static PipeValue Replace(PipeContext context)
        {
            string     needle      = (string)context.TakeArgument();
            string     replacement = null;
            PipeLambda fn          = context.TakeFunction();

            if (fn == null)
            {
                replacement = (string)context.TakeArgument();
            }

            EcmaScriptRegex re;

            if (EcmaScriptRegex.TryParse(needle, out re))
            {
                if (fn != null)
                {
                    return(re.Replace((string)context.Value, fn));
                }
                return(re.Replace((string)context.Value, replacement));
            }
            string str = (string)context.Value;
            int    pos = str.IndexOf(needle);

            if (pos >= 0)
            {
                return(String.Concat(str.Substring(0, pos), replacement, str.Substring(pos + needle.Length)));
            }
            return(context.Value);
        }
Exemple #2
0
        public static PipeValue Like(PipeValue str, PipeValue regex)
        {
            EcmaScriptRegex re;

            return(EcmaScriptRegex.TryParse((string)regex, out re) && re.Test((string)str));
        }