Beispiel #1
0
        public RString SubAt(params object[] args)
        {
            bool    iter    = false;
            RString repl    = null;
            bool    tainted = false;

/*
 *          if (args != null && args.Length == 1 && ruby.IsBlockGiven)
 *          {
 *              iter = true;
 *          }
 *          else
 */
            if (args != null && args.Length == 2)
            {
                repl    = StringToRString(ruby, args[1]);
                tainted = repl.IsTainted;
            }
            else
            {
                throw new eArgError(String.Format("wrong # of arguments({0} for 2)",
                                                  (args == null) ? 0 : args.Length));
            }
            RRegexp pat = GetPat(args[0]);

            if (pat.Search(ptr, 0, false, IsTainted) >= 0)
            {
                RThread    th    = ruby.GetCurrentContext();
                RMatchData match = (RMatchData)th.BackRef;
                int        beg   = match.Begin(0);
                int        len   = match.End(0) - beg;
                if (iter)
                {
/*
 *                  RRegexpClass.matchBusy(match);
 *                  repl = RString.AsRString(ruby, ruby.Yield(match[0]));
 *                  th.BackRef = match;        // rescue from yield.
 */
                }
                else
                {
                    repl = new RString(ruby, match.Sub(repl.ToString(), ptr));
                }
                if (repl.IsTainted)
                {
                    tainted = true;
                }
                StringBuilder sb = new StringBuilder(ptr);
                sb.Remove(beg, len);
                sb.Insert(beg, repl.ptr, 1);
                ptr = sb.ToString();
                if (tainted)
                {
                    Taint();
                }
                return(this);
            }
            return(null);
        }
Beispiel #2
0
        public int Search(string s, int pos, bool rev, bool stringTainted)
        {
            if (pos > s.Length)
            {
                return(-1);
            }

            RThread th = ruby.GetCurrentContext();

            Check();
            if (ruby.cRegexp.IsRecompileNeed)
            {
                checkPreparation();
            }
            Regex re = regex;

            if (rev)
            {
                re = new Regex(re.ToString(), re.Options | RegexOptions.RightToLeft);
            }
            Match m = re.Match(s, pos);

            if (m.Success == false)
            {
                th.BackRef = null;
                return(-1);
            }
            RMatchData mt = (RMatchData)th.BackRef;

            if (mt == null || mt.Test(RRegexpClass.MatchBusy))
            {
                mt = new RMatchData(ruby, s, m);
            }
            else
            {
/*
 *              if (th.safeLevel >= 3)
 *                  mt.Taint();
 *              else
 *                  mt.Untaint();
 */
                mt.SetData(s, m);
            }
            th.BackRef = mt;
            mt.Infect(this);
            if (stringTainted)
            {
                mt.Taint();
            }
            return(m.Index);
        }
Beispiel #3
0
        static private object s_lastmatch(RBasic r, params object[] args)
        {
            RThread    th = r.ruby.GetCurrentContext();
            RMatchData m  = (RMatchData)th.BackRef;

            if (m == null)
            {
                return(null);
            }
            string s = m[0];

            if (m.IsTainted)
            {
                return(new RString(r.ruby, s, true));
            }
            return(s);
        }
Beispiel #4
0
        static private object lastParenGetter(uint id, GlobalEntry gb, NetRuby rb)
        {
            RThread    th = rb.GetCurrentContext();
            RMatchData m  = (RMatchData)th.BackRef;

            if (m == null)
            {
                return(null);
            }
            string s = m.Last;

            if (m.IsTainted)
            {
                return(new RString(rb, s, true));
            }
            return(s);
        }
Beispiel #5
0
        public int Search(string s, int pos, bool rev, bool stringTainted)
        {
            if (pos > s.Length) return -1;

            RThread th = ruby.GetCurrentContext();
            Check();
            if (ruby.cRegexp.IsRecompileNeed)
                checkPreparation();
            Regex re = regex;
            if (rev)
            {
                re = new Regex(re.ToString(), re.Options | RegexOptions.RightToLeft);
            }
            Match m = re.Match(s, pos);
            if (m.Success == false)
            {
                th.BackRef = null;
                return -1;
            }
            RMatchData mt = (RMatchData)th.BackRef;
            if (mt == null || mt.Test(RRegexpClass.MatchBusy))
            {
                mt = new RMatchData(ruby, s, m);
            }
            else
            {
/*            
                if (th.safeLevel >= 3)
                    mt.Taint();
                else
                    mt.Untaint();
*/                    
                mt.SetData(s, m);
            }
            th.BackRef = mt;
            mt.Infect(this);
            if (stringTainted) mt.Taint();
            return m.Index;
        }
Beispiel #6
0
        public RString GsubAt(params object[] args)
        {
            bool    iter    = false;
            RString repl    = null;
            bool    tainted = false;

/*
 *          if (args != null && args.Length == 1 && ruby.IsBlockGiven)
 *          {
 *              iter = true;
 *          }
 *          else
 */
            if (args != null && args.Length == 2)
            {
                repl    = StringToRString(ruby, args[1]);
                tainted = repl.IsTainted;
            }
            else
            {
                throw new eArgError(String.Format("wrong # of arguments({0} for 2)",
                                                  (args == null) ? 0 : args.Length));
            }
            RRegexp pat = GetPat(args[0]);
            int     beg = pat.Search(ptr, 0, false, IsTainted);

            if (beg < 0)
            {
                return(null);
            }

            StringBuilder sb     = new StringBuilder();
            RThread       th     = ruby.GetCurrentContext();
            int           offset = 0;
            RMatchData    match  = null;

            while (beg >= 0)
            {
                string val;
                match = (RMatchData)th.BackRef;
                beg   = match.Begin(0);
                int len = match.End(0) - beg;

                /*
                 * if (iter)
                 * {
                 *
                 *  RRegexpClass.matchBusy(match);
                 *  repl = RString.AsRString(ruby, ruby.Yield(match[0]));
                 *  th.BackRef = match;        // rescue from yield.
                 *  if (repl.IsTainted) tainted = true;
                 *  val = repl.ToString();
                 *
                 * }
                 * else
                 */
                {
                    val = match.Sub(repl.ToString(), ptr);
                }
                if (beg > offset)
                {
                    sb.Append(ptr, offset, beg - offset);
                }
                sb.Append(val);
                if (len == 0)
                {
                    if (ptr.Length > match.End(0))
                    {
                        sb.Append(ptr, match.End(0), 1);
                    }
                    offset = beg + 1;
                }
                else
                {
                    offset = beg + len;
                }
                if (offset > ptr.Length)
                {
                    break;
                }
                beg = pat.Search(ptr, offset, false, IsTainted);
            }
            if (ptr.Length > offset)
            {
                sb.Append(ptr, offset, ptr.Length - offset);
            }
            th.BackRef = match;        // rescue from yield.
            ptr        = sb.ToString();
            if (tainted)
            {
                Taint();
            }
            return(this);
        }