Inheritance: ArrayObject
示例#1
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);
        }
示例#2
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;
        }