Esempio n. 1
0
        static internal void UpdateLastMatch(Match md, string input)
        {
            GroupCollection groups        = md.Groups;
            int             n             = groups.Count - 1;
            string          left_context  = Convert.ToString(input).Substring(0, md.Index);
            string          right_context = Convert.ToString(input).Substring(md.Index + md.Length);

            Ctr._lastmatch = md;
            Ctr.GetField("$_").SetValue("$_", input);
            Ctr.GetField("$&").SetValue("$&", md.Value);
            Ctr.GetField("$+").SetValue("$+", n > 0 ? groups [n].Value : "");
            Ctr.GetField("$`").SetValue("$`", left_context);
            Ctr.GetField("$'").SetValue("$'", right_context);
        }
Esempio n. 2
0
        internal void Initialize(string pattern, bool ignoreCase, bool global, bool multiLine)
        {
            RegExpConstructor ctr = RegExpConstructor.Ctr;

            _source     = pattern;
            _ignoreCase = ignoreCase;
            _global     = global;
            _multiline  = multiLine || Convert.ToBoolean(ctr.GetField("$*").GetValue("$*"));

            RegexOptions options = RegexOptions.ECMAScript | RegexOptions.Compiled;

            if (ignoreCase)
            {
                options |= RegexOptions.IgnoreCase;
            }
            if (_multiline)
            {
                options |= RegexOptions.Multiline;
            }
            try {
                regex = new Regex(source, options);
            } catch (ArgumentException err) {
                throw new JScriptException(JSError.RegExpSyntax, err.Message);
            }
        }
Esempio n. 3
0
        public static object exec(object thisObj, object input)
        {
            RegExpObject re  = Convert.ToRegExp(thisObj);
            string       str = null;

            if (input == null)
            {
                RegExpConstructor ctr = RegExpConstructor.Ctr;
                str = Convert.ToString(ctr.GetField("$_").GetValue("$_"));
            }
            else
            {
                str = Convert.ToString(input);
            }
            bool global    = re.global;
            int  lastIndex = global ? (int)((double)re.lastIndex) : 0;
            bool success   = lastIndex >= 0 && lastIndex <= str.Length;

            Match md = null;

            if (success)
            {
                md      = re.regex.Match(str, lastIndex);
                success = md.Success;
            }

            if (!success)
            {
                re.lastIndex = 0;
                return(DBNull.Value);
            }

            int index    = md.Index;
            int endIndex = index + md.Length;

            if (global)
            {
                re.lastIndex = endIndex;
            }
            RegExpConstructor.UpdateLastMatch(md, str);

            GroupCollection caps   = md.Groups;
            uint            len    = (uint)caps.Count;
            RegExpMatch     result = new RegExpMatch();

            result.AddField("index", index);
            result.AddField("input", input);
            result.length = len;
            for (uint j = 0; j < len; j++)
            {
                result.elems [j] = caps [(int)j].Value;
            }

            return(result);
        }