public virtual P5List Slice(Runtime runtime, P5Array keys) { var res = new P5List(runtime); var list = new List<IP5Any>(keys.GetCount(runtime)); bool found = false; foreach (var key in keys) { int i = key.AsInteger(runtime); if (i < array.Count) found = true; list.Add(GetItemOrUndef(runtime, key, false)); } if (found) res.SetArray(list); return res; }
public P5List Slice(Runtime runtime, P5Array keys, bool create) { var res = new P5List(runtime, (List<IP5Any>) null); var list = new List<IP5Any>(); foreach (var key in keys) { list.Add(GetItemOrUndef(runtime, key, create)); } res.SetArray(list); return res; }
public static P5Scalar AnonymousHash(Runtime runtime, P5List list) { var clone = list.Clone(runtime, 1) as IP5Enumerable; return new P5Scalar(runtime, new P5Hash(runtime, clone)); }
public static P5List SplitSpaces(Runtime runtime, IP5Any value) { var str = value.AsString(runtime); var res = new P5List(runtime); int start = 0, curr = 0; for ( ; curr < str.Length; ) { for ( ; curr < str.Length && char.IsWhiteSpace(str[curr]); ++curr) ; start = curr; if (start == str.Length) break; for ( ; curr < str.Length && !char.IsWhiteSpace(str[curr]); ++curr) ; res.Push(runtime, new P5Scalar(runtime, str.Substring(start, curr - start))); } return res; }
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; }