public static IP5Any MatchHelper(IP5Regex regex, Runtime runtime, IP5Any value, int flags, Opcode.ContextValues cxt, ref RxResult oldState) { bool match = regex.MatchString(runtime, value.AsString(runtime), -1, false, ref oldState); if (cxt != Opcode.ContextValues.LIST) { return new P5Scalar(runtime, match); } else if (match && runtime.LastMatch.StringCaptures.Length > 0) { var res = new IP5Any[runtime.LastMatch.StringCaptures.Length]; for (int i = 0; i < runtime.LastMatch.StringCaptures.Length; ++i) res[i] = new P5Scalar(runtime, runtime.LastMatch.StringCaptures[i]); return new P5List(runtime, res); } else { return new P5List(runtime, match); } }
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; }