static internal object s_new(RBasic r, params object[] args) { RRegexp re = new RRegexp(r.ruby, (RMetaObject)r); r.ruby.CallInit(re, args); return(re); }
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); }
internal void Initialize(RRegexp r, RegexOptions fl) { regex = r.regex; if (regex.Options != fl) { regex = new Regex(regex.ToString(), fl); } }
static internal object initialize(RBasic r, params object[] args) { if (args.Length < 1 || args.Length > 3) { throw new eArgError("wrong # of argument"); } RegexOptions flag = RegexOptions.None; if (args.Length >= 2) { if (args[1] is int || args[1] is RegexOptions) { flag = (RegexOptions)(int)args[1]; } else if (args[1] is RFixnum) { flag = (RegexOptions)((RFixnum)args[1]).ToInt(); } else if (RBasic.RTest(args[1])) { flag = RegexOptions.IgnoreCase; } } if (args.Length == 3) { // ignore char set } NetRuby ruby = r.ruby; RRegexp self = (RRegexp)r; if (args[0] is RRegexp) { RRegexp re = (RRegexp)args[0]; re.Check(); self.Initialize(re, flag); } else { string p = RString.ToString(ruby, args[0]); self.Initialize(p, flag); } return(self); }
public override bool Equals(object o) { if (base.Equals(o)) { return(true); } if (o is RRegexp == false) { return(false); } RRegexp re = (RRegexp)o; Check(); re.Check(); if (re.regex.ToString() != regex.ToString() || re.regex.Options != regex.Options) { return(false); } return(true); }
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); }
static internal object s_new(RBasic r, params object[] args) { RRegexp re = new RRegexp(r.ruby, (RMetaObject)r); r.ruby.CallInit(re, args); return re; }