Jint.Native.JsRegExpConstructor.ExecImpl C# (CSharp) Method

ExecImpl() public method

public ExecImpl ( JsRegExp regexp, JsInstance parameters ) : JsInstance
regexp JsRegExp
parameters JsInstance
return JsInstance
        public JsInstance ExecImpl(JsRegExp regexp, JsInstance[] parameters)
        {
            JsArray A = Global.ArrayClass.New();
            string input = parameters[0].ToString();
            A["input"] = Global.StringClass.New(input);

            int i = 0;
            MatchCollection matches = Regex.Matches(input, regexp.Pattern, regexp.Options);
            if (matches.Count > 0) {
                if (regexp.IsGlobal) {
                    foreach (Match m in matches) {
                        A[Global.NumberClass.New(i++)] = Global.StringClass.New(m.Value);
                    }
                }
                else {
                    foreach (Group g in matches[0].Groups) {
                        A[Global.NumberClass.New(i++)] = Global.StringClass.New(g.Value);
                    }
                }

                A["index"] = Global.NumberClass.New(matches[0].Index);
            }

            return A;
        }