예제 #1
0
파일: pcre.cs 프로젝트: iolevel/peachpie
        public static PhpArray preg_grep(Context ctx, string pattern, PhpArray input, int flags = 0)
        {
            if (input == null)
            {
                return null;
            }

            var result = new PhpArray(input.Count);

            if (input.Count != 0)
            {
                var regex = new PerlRegex.Regex(pattern);

                var enumerator = input.GetFastEnumerator();
                while (enumerator.MoveNext())
                {
                    var str = enumerator.CurrentValue.ToStringOrThrow(ctx);
                    var m = regex.Match(str);

                    // move a copy to return array if success and not invert or
                    // not success and invert
                    if (m.Success ^ (flags & PREG_GREP_INVERT) != 0)
                    {
                        result.Add(enumerator.CurrentKey, enumerator.CurrentValue.DeepCopy());
                    }
                }
            }

            //
            return result;
        }
예제 #2
0
파일: pcre.cs 프로젝트: iolevel/peachpie
 public static int preg_match(Context ctx, string pattern, string subject)
 {
     var regex = new PerlRegex.Regex(pattern);
     return regex.Match(subject).Success ? 1 : 0;
 }