public void parser(Owner owner, string text, Config config, List <NodeBase> vList, System.Func <TagAttributes, IExternalNode> getExternalNode) { if (string.IsNullOrEmpty(text)) { return; } if (config.font == null) { Debug.LogError("TextParser pFont == null"); return; } clear(); mOwner = owner; this.getExternalNode = getExternalNode; d_nodeList = vList; startConfig.Set(config); currentConfig.Set(config); int lenght = text.Length; while (lenght > d_curPos) { if (d_bBegin == false) { switch (text[d_curPos]) { case '#': { // 未遇到功能字符,开始功能字符的解析 d_bBegin = true; ++d_curPos; } break; case '<': { int endpos = text.IndexOf('>', d_curPos); if (endpos != -1) { string tag = null; string param = null; int tagend = text.IndexOfAny(s_tag_key, d_curPos); if (tagend != -1 && tagend < endpos) { tag = text.Substring(d_curPos + 1, tagend - d_curPos); param = text.Substring(tagend + 1, endpos - tagend - 1); } else { tag = text.Substring(d_curPos + 1, endpos - d_curPos - 1); } var func = GetTagAction(tag); if (func != null) { if (d_text.Length != 0) { save(false); } func(tag, param); d_curPos = endpos + 1; break; } } d_text.Append(text[d_curPos]); ++d_curPos; } break; case '\n': { // 这个是换行 save(true); d_curPos++; } break; default: { d_text.Append(text[d_curPos]); ++d_curPos; } break; } } else { char c = text[d_curPos]; OnFun fun = null; if (c < 128 && ((fun = OnFuns[c]) != null)) { fun(text); } else if (!ParserCartoon(text)) { d_text.Append(text[d_curPos]); ++d_curPos; } d_bBegin = false; } } if (d_text.Length != 0) { save(false); } clear(); }
public void parser(Owner owner, string text, Config config, List <NodeBase> vList) { clear(); mOwner = owner; d_nodeList = vList; startConfig.Set(config); currentConfig.Set(config); if (currentConfig.font == null) { Debug.LogError("TextParser pFont == null"); return; } if (string.IsNullOrEmpty(text)) { return; } int lenght = text.Length; while (lenght > d_curPos) { if (d_bBegin == false) { switch (text[d_curPos]) { case '#': { // 未遇到功能字符,开始功能字符的解析 d_bBegin = true; ++d_curPos; } break; case '<': { int endpos = text.IndexOf('>', d_curPos); if (endpos != -1) { string tag = null; string param = null; int tagend = text.IndexOfAny(new char[] { ' ', '=' }, d_curPos); if (tagend != -1 && tagend < endpos) { tag = text.Substring(d_curPos + 1, tagend - d_curPos); param = text.Substring(tagend + 1, endpos - tagend - 1); } else { tag = text.Substring(d_curPos + 1, endpos - d_curPos - 1); } if (d_text.Length != 0) { save(false); } TagParam(tag, param); d_curPos = endpos + 1; break; } else { d_text.Append(text[d_curPos]); } ++d_curPos; } break; case '\n': { // 这个是换行 save(true); d_curPos++; } break; default: { d_text.Append(text[d_curPos]); ++d_curPos; } break; } } else { char c = text[d_curPos]; OnFun fun = null; if (c < 128 && ((fun = OnFuns[c]) != null)) { fun(text); } else { d_text.Append(text[d_curPos]); ++d_curPos; } d_bBegin = false; } } if (d_text.Length != 0) { save(false); } clear(); }