public BETag(string s) { OK = false; if (s == null) { return; } if (s.StartsWith("{")) { BEPos bp = BETag.FormatCmd(s, '{', '}'); if (bp.Valid()) { Cmd = new Cmd(bp.String); //////////??????? s = s.Substring(bp.E + 1); } } string[] items = s.Split(new string[] { "[", "]", "-" }, StringSplitOptions.RemoveEmptyEntries); if (items.Length == 2) { Begin = items[0].Replace("@@", "-").Replace("##<", "{").Replace(">##", "}"); End = items[1].Replace("@@", "-").Replace("##<", "{").Replace(">##", "}"); } else if (items.Length == 1) { Begin = items[0].Replace("@@", "-").Replace("##<", "{").Replace(">##", "}"); End = ""; } else { return; } OK = true; }
public BEPos NextBEPos(BEPos bp) //同一个才能NextBEPos { string s = bp.InnerStr; if (!OK || !bp.Valid() || s == null) { return(new BEPos(-1, -1, s)); } int B = s.IndexOf(Begin, bp.E + End.Length); if (B == -1) { return(new BEPos(-1, -1, s)); } B = B + Begin.Length; int E = s.IndexOf(End, B); if (E == -1) { return(new BEPos(-1, -1, s)); } return(new BEPos(B, E, s)); }
public BEPos BEPos(BEPos bp) //ReverseMatch { string s = bp.InnerStr; if (!OK || s == null || !bp.Valid()) { return(new BEPos(-1, -1, s)); } int B = s.IndexOf(Begin, bp.B); if (Cmd != null && Cmd.ReverseMatch) { B = s.LastIndexOf(Begin, bp.B, bp.E - bp.B); } if (B != -1 && B < bp.E) { B = B + Begin.Length; int E = s.IndexOf(End, B, bp.E - B); if (E != -1) { return(new BEPos(B, E, s)); } } B = s.LastIndexOf(Begin, bp.E, bp.E - bp.B); if (B != -1) { B = B + Begin.Length; int E = s.IndexOf(End, B, bp.E - B); if (E != -1) { return(new BEPos(B, E, s)); } } return(new BEPos(-1, -1, s)); }
public Cmd(string str) { string[] items = str.Split(new string[] { ";\r\n" }, StringSplitOptions.RemoveEmptyEntries); cmdkeyvalue = new Dictionary <string, string>(); foreach (string s in items) { if (s.Contains("=")) { string name = s.Substring(0, s.IndexOf('=')).Trim(); if (ValidTools.ValidName(name) && !cmdkeyvalue.ContainsKey(name)) { cmdkeyvalue[name] = s.Substring(s.IndexOf('=') + 1); } } } if (cmdkeyvalue.ContainsKey("replacetonull")) { ReplacetoNullTags = new BETags(cmdkeyvalue["replacetonull"]); } if (cmdkeyvalue.ContainsKey("addprefix")) { Prefix = cmdkeyvalue["addprefix"]; } if (cmdkeyvalue.ContainsKey("addsubfix")) { Subfix = cmdkeyvalue["addsubfix"]; } return; /////////////////////////////// if (cmdkeyvalue.ContainsKey("nexturl")) { NextUrlTags = new BETags(cmdkeyvalue["nexturl"]); } if (cmdkeyvalue.ContainsKey("nextexist")) { NextExist = cmdkeyvalue["nextexist"]; } if (cmdkeyvalue.ContainsKey("replacetemplate")) { ReplaceTemplate = cmdkeyvalue["replacetemplate"]; ReplaceTemplate = ReplaceTemplate.Replace("\\r\\n", "\r\n") .Replace("\\t", "\t"); } if (cmdkeyvalue.ContainsKey("multisubitem")) { MultiSubItemTags = new BETags(cmdkeyvalue["multisubitem"]); } if (cmdkeyvalue.ContainsKey("reversematch")) { if (cmdkeyvalue["reversematch"] == "true") { ReverseMatch = true; } } if (cmdkeyvalue.ContainsKey("txtasurl")) { if (cmdkeyvalue["txtasurl"] == "true") { TxtAsUrl = true; } } if (cmdkeyvalue.ContainsKey("dbidbeginend")) { BETags bts = new BETags(cmdkeyvalue["dbidbeginend"]); Bedbid = null; if (bts.tags.Count == 1 && ValidTools.ValidNumber(bts.tags[0].Begin) && ValidTools.ValidNumber(bts.tags[0].End)) { Bedbid = new BEId(); Bedbid.B = Convert.ToInt32(bts.tags[0].Begin); Bedbid.E = int.MaxValue; if (ValidTools.ValidNumber(bts.tags[0].End)) { Bedbid.E = Convert.ToInt32(bts.tags[0].End); } Bedbid.MoveToTop(); }//else 未设置BeDbid } if (cmdkeyvalue.ContainsKey("savepath")) { SavePath = cmdkeyvalue["savepath"]; } if (cmdkeyvalue.ContainsKey("downloadsuburl")) { string downloadsuburl = cmdkeyvalue["downloadsuburl"]; if (downloadsuburl.ToLower().Trim() == "true") { DownLoadSuburl = true; DownLoadSuburlType = "auto"; if (cmdkeyvalue.ContainsKey("downloadsuburltype")) { DownLoadSuburlType = cmdkeyvalue["downloadsuburltype"].Trim(); } } } if (cmdkeyvalue.ContainsKey("casecmd")) { BEPos bp = BETag.FormatCmd(cmdkeyvalue["casecmd"], '{', '}'); if (bp.Valid()) { string cmdstr = bp.String; caseCmd = new CaseCmd(cmdstr); } } if (cmdkeyvalue.ContainsKey("table")) { BEPos bp = BETag.FormatCmd(cmdkeyvalue["table"], '{', '}'); if (bp.Valid()) { string tablecmdstr = bp.String; tableCmd = new TableCmd(tablecmdstr); ListTable.Add(tableCmd); // 以后可以添加多个Table } } if (cmdkeyvalue.ContainsKey("tablevalue")) { BEPos bp = BETag.FormatCmd(cmdkeyvalue["tablevalue"], '{', '}'); if (bp.Valid()) { string tablecmdstr = bp.String; tablevalueCmd = new TableValueCmd(tablecmdstr); } } }