Beispiel #1
0
        public static IP5Any MatchGlobalHelper(IP5Regex regex, Runtime runtime, IP5Any value, int flags,
                                               Opcode.ContextValues cxt, ref RxResult oldState)
        {
            var scalar = value as P5Scalar;
            bool pos_set;
            int pos = value.GetPos(runtime, out pos_set);
            string str = value.AsString(runtime);
            bool match;
            IP5Any result;

            if (cxt != Opcode.ContextValues.LIST)
            {
                match = regex.MatchString(runtime, str, pos, pos_set,
                                          ref oldState);

                result = new P5Scalar(runtime, match);

                if (scalar != null)
                {
                    if (match)
                        scalar.SetPos(runtime, runtime.LastMatch.End, false);
                    else if ((flags & Opcode.RX_KEEP) == 0)
                        scalar.UnsetPos(runtime);
                }
            }
            else
            {
                var capt = new List<IP5Any>();

                for (;;)
                {
                    match = regex.MatchString(runtime, str,
                                              pos, pos_set, ref oldState);
                    if (match)
                    {
                        if (runtime.LastMatch.StringCaptures != null)
                        {
                            foreach (var s in runtime.LastMatch.StringCaptures)
                                capt.Add(new P5Scalar(runtime, s));
                        }
                        else
                        {
                            string s = str.Substring(runtime.LastMatch.Start,
                                                     runtime.LastMatch.End - runtime.LastMatch.Start);
                            capt.Add(new P5Scalar(runtime, s));
                        }
                    }
                    else
                        break;

                    pos = runtime.LastMatch.End;
                }

                if (scalar != null)
                {
                    if ((flags & Opcode.RX_KEEP) != 0)
                        scalar.SetPos(runtime, pos, false);
                    else
                        scalar.UnsetPos(runtime);
                }

                result = new P5List(runtime, capt);
            }

            return result;
        }