public Pile <Reach> split(string delim) { Reach res = this; Pile <Reach> ret = new Pile <Reach>(); while (res.len > 0) { Reach part = res.before(1, utl.dmyBool("al(occur, token) is planned"), delim); res = res.after(1, utl.dmyBool("al(occur, token) is planned"), delim); ret.Add(part); } return(ret); }
private static void selfTest() { selfTested = true; Reach r1 = new Reach("ab"); Reach r2 = new Reach("..X--XX___XX,,XX"); Reach r3 = new Reach("aa bb cc "); ass(r3.firstWord(" ").equals("")); ass(r3.firstWord(" a").equals("aa ")); ass(r3.lastWord(" ").equals(" ")); ass(r2.upto(1, false, "X,", "X_", "X-").equals("..X-")); ass(r2.upto(2, false, "X,", "X_", "X-").equals("..X--XX_")); ass(r2.upto(3, false, "X,", "X_", "X-").equals("..X--XX___XX,")); ass(r2.upto(-1, false, "X,", "X_", "X-").equals("..X--XX___XX,")); ass(r2.upto(-2, false, "X,", "X_", "X-").equals("..X--XX_")); ass(r2.upto(-3, false, "X,", "X_", "X-").equals("..X-")); ass(r2.upto(1, false, ",XX", "_XX", "X-", "..").equals("..")); ass(r2.upto(2, false, ",XX", "_XX", "X-", "..").equals("..X-")); ass(r2.upto(3, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX")); ass(r2.upto(-1, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX,,XX")); ass(r2.upto(-2, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX")); ass(r2.upto(-3, false, ",XX", "_XX", "X-", "..").equals("..X-")); ass(r2.from(1, false, "X,", "X_", "X-").equals("X--XX___XX,,XX")); ass(r2.from(2, false, "X,", "X_", "X-").equals("X___XX,,XX")); ass(r2.from(3, false, "X,", "X_", "X-").equals("X,,XX")); ass(r2.from(-1, false, "X,", "X_", "X-").equals("X,,XX")); ass(r2.from(-2, false, "X,", "X_", "X-").equals("X___XX,,XX")); ass(r2.from(-3, false, "X,", "X_", "X-").equals("X--XX___XX,,XX")); ass(r2.from(1, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX,,XX")); ass(r2.from(2, false, ",XX", "_XX", "X-", "..").equals("X--XX___XX,,XX")); ass(r2.from(3, false, ",XX", "_XX", "X-", "..").equals("_XX,,XX")); ass(r2.from(-1, false, ",XX", "_XX", "X-", "..").equals(",XX")); ass(r2.from(-2, false, ",XX", "_XX", "X-", "..").equals("_XX,,XX")); ass(r2.from(-3, false, ",XX", "_XX", "X-", "..").equals("X--XX___XX,,XX")); ass(r1.upto(1).equals("a")); ass(r1.before(1).equals("")); ass(r1.from(1).equals("ab")); ass(r1.after(1).equals("b")); ass(r1.upto(-1).equals("ab")); ass(r1.before(-1).equals("a")); ass(r1.from(-1).equals("b")); ass(r1.after(-1).equals("")); ass(r2.upto(2, true, "XX").equals("..X--XX___XX")); ass(r2.upto(2, true, "X").equals("..X--X")); ass(r2.upto(2, true, "XX", "X").equals("..X--X")); ass(r2.upto(2, true, "X", "XX").equals("..X--X")); ass(r2.upto(-2, true, "XX").equals("..X--XX___XX")); ass(r2.upto(-2, true, "X").equals("..X--XX___XX,,X")); ass(r2.upto(-2, true, "XX", "X").equals("..X--XX___XX,,X")); ass(r2.upto(-2, true, "X", "XX").equals("..X--XX___XX,,X")); ass(r2.from(2, true, "XX").equals("XX,,XX")); ass(r2.from(2, true, "X").equals("XX___XX,,XX")); ass(r2.from(2, true, "XX", "X").equals("XX___XX,,XX")); ass(r2.from(2, true, "X", "XX").equals("XX___XX,,XX")); ass(r2.from(-2, true, "XX").equals("XX,,XX")); ass(r2.from(-2, true, "X").equals("XX")); ass(r2.from(-2, true, "XX", "X").equals("XX")); ass(r2.from(-2, true, "X", "XX").equals("XX")); ass(r2.before(2, true, "XX").equals("..X--XX___")); ass(r2.before(2, true, "X").equals("..X--")); ass(r2.before(2, true, "XX", "X").equals("..X--")); ass(r2.before(2, true, "X", "XX").equals("..X--")); ass(r2.before(-2, true, "XX").equals("..X--XX___")); ass(r2.before(-2, true, "X").equals("..X--XX___XX,,")); ass(r2.before(-2, true, "XX", "X").equals("..X--XX___XX,,")); ass(r2.before(-2, true, "X", "XX").equals("..X--XX___XX,,")); ass(r2.after(2, true, "XX").equals(",,XX")); ass(r2.after(2, true, "X").equals("X___XX,,XX")); ass(r2.after(2, true, "XX", "X").equals("X___XX,,XX")); ass(r2.after(2, true, "X", "XX").equals("X___XX,,XX")); ass(r2.after(-2, true, "XX").equals(",,XX")); ass(r2.after(-2, true, "X").equals("X")); ass(r2.after(-2, true, "XX", "X").equals("X")); ass(r2.after(-2, true, "X", "XX").equals("X")); ass(r2.at(2, true, "XX").equals("XX")); ass(r2.at(2, true, "X").equals("X")); ass(r2.at(2, true, "XX", "X").equals("X")); ass(r2.at(2, true, "X", "XX").equals("X")); ass(r2.at(-2, true, "XX").equals("XX")); ass(r2.at(-2, true, "X").equals("X")); ass(r2.at(-2, true, "XX", "X").equals("X")); ass(r2.at(-2, true, "X", "XX").equals("X")); }
public Reach Load() { return(Reach.Load(location.ToString())); }
public Reach from(Reach other) { Base.upd(); other.upd(); return((pure) ? (bufop)? (Reach)Base.rplfrom_(other, this) : (Reach)Base.rplfrom(other, this) : (bufop) ? (Reach)Base.rplfrom(other, (Rch)rTxt) : (Reach)Base.rplfrom(other, (Rch)rTxt)); }
// ******************* (Rch other) public Reach before(Reach other) { Base.upd(); other.upd(); return((pure) ? (bufop)? (Reach)Base.rplbefore_(other, this) : (Reach)Base.rplbefore(other, this) : (bufop) ? (Reach)Base.rplbefore(other, (Rch)rTxt) : (Reach)Base.rplbefore(other, (Rch)rTxt)); }
internal ReplaceWith(bool bufop, Reach Base, string txt) { this.bufop = bufop; this.Base = Base; sTxt = txt; pure = true; }
public Reach from(Reach other) { Base.upd(); other.upd(); return((pure) ? (bufop) ? (Reach)Base.delfrom_(other) : (Reach)Base.delfrom(other) : (bufop) ? (Reach)Base.delfrom_(other, this) : (Reach)Base.delfrom(other, this)); }
internal Delete(bool bufop, Reach Base, int cnt) { this.bufop = bufop; this.Base = Base; this.cnt = cnt; pure = false; }
public Reach after(Reach other) { Base.upd(); other.upd(); return((strong) ? (Reach)Base.after__(other) : (Reach)Base.after_(other)); }
public Reach after(Reach other) { upd(); other.upd(); return((Reach)base.after(other)); }
public Reach from(Reach other) { upd(); other.upd(); return((Reach)base.from(other)); }
public Reach at(Reach other) { upd(); other.upd(); return((Reach)base.at(other)); }
public Reach upto(Reach other) { upd(); other.upd(); return((Reach)base.upto(other)); }
// ******************* (Rch other) public Reach before(Reach other) { upd(); other.upd(); return((Reach)base.before(other)); }
public static Reach Load(string uri) { Reach Uri = new Reach(uri); uri = Uri.before(1, "///?"); byte[] post = new ASCIIEncoding().GetBytes(Uri.after(1, "///?")); Uri location = new Uri(uri); if (location.IsFile) { Reach ret = new Reach(utl.f2s(location.ToString())); ret.location = location; return(ret); } else { HttpWebRequest req; HttpWebResponse resp; Encoding enc; req = (HttpWebRequest)WebRequest.Create(location.ToString()); req.CookieContainer = new CookieContainer(); req.CookieContainer.Add(Cookies); req.Timeout = 30000; // 30 secs req.UserAgent = "Internet Explorer"; if (post.Length > 0) { req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = post.Length; req.GetRequestStream().Write(post, 0, post.Length); } try { resp = (HttpWebResponse)req.GetResponse(); Cookies.Add(resp.Cookies); Reach ret = null; try { Stream responseStream = resp.GetResponseStream(); Encoding e = Encoding.GetEncoding(resp.CharacterSet); StreamReader reader = new StreamReader(responseStream, e); string s = reader.ReadToEnd(); ret = new Reach(s); } catch { //enc = Encoding.GetEncoding(1252); // Windows-1252 or iso //enc = Encoding.GetEncoding("unicodeFFFE"); // 1201 = "UTF-16BE" or "unicodeFFFE" enc = Encoding.GetEncoding("unicode"); // 1200 = "UTF-16LE", "utf-16", "ucs-2", "unicode", or "ISO-10646-UCS-2" try { if (resp.ContentEncoding.Length > 0) { enc = Encoding.GetEncoding(resp.ContentEncoding); } } catch (Exception e) { e.ToString(); } ret = new Reach((new StreamReader(resp.GetResponseStream())).ReadToEnd()); } ret.location = location; return(ret); } catch (Exception e) { utl.msg(" ******* CANNOT LOAD DOCUMENT FROM WEB ********" + e.ToString()); return(null); //SleepEx(20000, 1); //debug } } }
public Reach at(Reach other) { Base.upd(); other.upd(); return((strong) ? (Reach)Base.at__(other) : (Reach)Base.at_(other)); }
public Reach from(Reach other) { Base.upd(); other.upd(); return((strong) ? (Reach)Base.from__(other) : (Reach)Base.from_(other)); }
public bool Equals(Reach other) { upd(); other.upd(); return(base.Equals((Rch)other)); }
internal Delete(bool bufop, Reach Base) { this.bufop = bufop; this.Base = Base; pure = true; }
internal Insert(bool bufop, Reach Base, string txt) { this.bufop = bufop; this.Base = Base; sTxt = txt; pure = true; }
public Reach upto(Reach other) { Base.upd(); other.upd(); return((pure) ? (bufop) ? (Reach)Base.delupto_(other) : (Reach)Base.delupto(other) : (bufop) ? (Reach)Base.delupto_(other, this) : (Reach)Base.delupto(other, this)); }
internal Insert(bool bufop, Reach Base, Reach txt) { this.bufop = bufop; this.Base = Base; rTxt = txt; pure = false; rTxt.upd(); }
public Reach after(Reach other) { Base.upd(); other.upd(); return((pure) ? (bufop) ? (Reach)Base.delafter_(other) : (Reach)Base.delafter(other) : (bufop) ? (Reach)Base.delafter_(other, this) : (Reach)Base.delafter(other, this)); }
internal Extract(Reach Base) { this.Base = Base; }
internal ReplaceWith(bool bufop, Reach Base, Reach txt) { this.bufop = bufop; this.Base = Base; rTxt = txt; pure = false; rTxt.upd(); }
// ******************* (Rch other) public Reach before(Reach other) { Base.upd(); other.upd(); return((strong) ? (Reach)Base.before__(other) : (Reach)Base.before_(other)); }
public Reach upto(Reach other) { Base.upd(); other.upd(); return((pure) ? (bufop)? (Reach)Base.rplupto_(other, this) : (Reach)Base.rplupto(other, this) : (bufop) ? (Reach)Base.rplupto(other, (Rch)rTxt) : (Reach)Base.rplupto(other, (Rch)rTxt)); }
public Reach upto(Reach other) { Base.upd(); other.upd(); return((strong) ? (Reach)Base.upto__(other) : (Reach)Base.upto_(other)); }
public Reach after(Reach other) { Base.upd(); other.upd(); return((pure) ? (bufop)? (Reach)Base.rplafter_(other, this) : (Reach)Base.rplafter(other, this) : (bufop) ? (Reach)Base.rplafter(other, (Rch)rTxt) : (Reach)Base.rplafter(other, (Rch)rTxt)); }
internal Reach(Reach source, Restrict rt) : base(source, rt) { init(); }