/// <summary> /// JSON分析标签 /// </summary> /// <param name="parser">TemplateParser</param> /// <param name="tc">Token集合</param> /// <returns></returns> public ITag Parse(TemplateParser parser, TokenCollection tc) { if (tc.Count > 2 && (tc[0].TokenKind == TokenKind.LeftBrace) && tc.Last.TokenKind == TokenKind.RightBrace) { JsonTag tag = new JsonTag(); TokenCollection[] tcs = tc.Split(1, tc.Count - 1, TokenKind.Comma); for (int i = 0; i < tcs.Length; i++) { if (tcs[i].Count == 1 && tcs[i][0].TokenKind == TokenKind.Comma) { continue; } TokenCollection[] keyValuePair = tcs[i].Split(0, tcs[i].Count, TokenKind.Colon); if (keyValuePair.Length != 3) { //不符合规范 return(null); } var key = parser.Read(keyValuePair[0]); var value = parser.Read(keyValuePair[2]); tag.Dict.Add(key, value); } return(tag); } return(null); }
public int String2decimal(ref int refPos, Byte[] src, bool minus = false) { // String2double copy if (minus) { doubleOrString.pos = refPos - 1; } else { doubleOrString.pos = refPos; } #if !SKIP_VALIDATION if (src[refPos] == '0' && SearchTables.valTypes[src[refPos + 1]] == 4) { return(refPos); } #endif while (SearchTables.valTypes[src[refPos]] == 4) { refPos++; } if (src[refPos] == '.') { ++refPos; while (SearchTables.valTypes[src[refPos]] == 4) { refPos++; } } if (SearchTables.valTypes[src[refPos]] == 5) { ++refPos; if (src[refPos] == '+' || src[refPos] == '-') { ++refPos; } #if !SKIP_VALIDATION if (SearchTables.valTypes[src[refPos]] != 4) { return(--refPos); } #endif while (SearchTables.valTypes[src[refPos]] == 4) { refPos++; } } Tag = JsonTag.JSON_NUMBER_STR; doubleOrString.length = refPos - doubleOrString.pos; return(refPos); }
//[MethodImpl(MethodImplOptions.AggressiveInlining)] public void ListToValue(JsonTag tag, JsonNode tail) { Tag = tag; JsonNode head = tail; if (null != head) { head = tail.next; tail.next = null; node = head; doubleOrString = head.doubleOrString; } }
public Tag Parse(TemplateParser parser, TokenCollection tc) { if (ParserHelpers.IsEqual(tc.First.Text, Field.KEY_JSON)) { if (tc.Count > 2 && (tc[1].TokenKind == TokenKind.LeftParentheses) && tc.Last.TokenKind == TokenKind.RightParentheses) { Tag vtag = parser.Read(new TokenCollection(tc, 2, tc.Count - 2)); JsonTag tag = new JsonTag(); tag.Json = vtag; return(tag); } } return(null); }
public void ListToValue(JsonTag tag, JsonNode tail) { // this=parent, tails[pos]=last, 1st, ... Tag = tag; JsonNode head = tail; if (null != head) { head = tail.next; // 1st one tail.next = null; // last -> next => cut end #if DoubleLinked head.pred = null; // Remove pred of 1st one #endif node = head; // attach to parent #if DoubleLinked head.parent = this; // and #endif doubleOrString.data = 0; // clear parent's value } else if (tag == JsonTag.JSON_ARRAY) { doubleOrString.data = 0; // clear key value } }
public JsonErrno GetString(ref int refPos, Byte[] src) { doubleOrString.pos = refPos; int end = refPos; while (src[end] != '"') { if (src[end] == '\\') { end++; if (src[end] == 'u') { end += 4; #if !SKIP_VALIDATION } else { // or \\,\"./,\b\f\n\r\t if ("\\\"/bfnrt".IndexOf((char)src[end]) < 0) { return(JsonErrno.BAD_STRING); } #endif } } #if !SKIP_VALIDATION else if (src[end] < ' ') { return(JsonErrno.BAD_STRING); } #endif end++; } doubleOrString.length = end - refPos; refPos = end + 1; this.Tag = JsonTag.JSON_STRING; return(JsonErrno.OK); }
public int String2double(ref int refPos, Byte[] src, bool minus = false) { // -[0-9]*.[0-9]+[eE][0-9]+ doubleOrString.data = 0; // number = 0 #if !SKIP_VALIDATION if (src[refPos] == '0' && SearchTables.valTypes[src[refPos + 1]] == 4) { return(refPos); } #endif while (SearchTables.valTypes[src[refPos]] == 4) { doubleOrString.number = (doubleOrString.number * 10) + (src[refPos++] - '0'); } if (src[refPos] == '.') { ++refPos; double fraction = 1; while (SearchTables.valTypes[src[refPos]] == 4) { fraction *= 0.1; doubleOrString.number += (src[refPos++] - '0') * fraction; } } if (SearchTables.valTypes[src[refPos]] == 5) { ++refPos; double vbase = 10; if (src[refPos] == '+') { ++refPos; } else if (src[refPos] == '-') { ++refPos; vbase = 0.1; } uint exponent = 0; #if !SKIP_VALIDATION if (SearchTables.valTypes[src[refPos]] != 4) { return(--refPos); } #endif while (SearchTables.valTypes[src[refPos]] == 4) { exponent = (exponent * 10) + ((uint)src[refPos++] - '0'); } double power = 1; for (; exponent != 0; exponent >>= 1, vbase *= vbase) { if ((exponent & 1) != 0) { power *= vbase; } } doubleOrString.number *= power; } if (minus) { doubleOrString.number = -doubleOrString.number; } Tag = JsonTag.JSON_NUMBER; return(refPos); }
/// <summary> /// 测试标签 /// </summary> /// <param name="text">文本(经过格式化)</param> /// <param name="origin">原始文本</param> /// <param name="regex">正则表达式</param> /// <param name="type">目标标签类型</param> private void MatchTag(string text, string origin, Regex regex, TagType type) { if (this.Config.tagregex.TagPairEndTest.IsMatch(text) || this.Config.tagregex.EmptyTest.IsMatch(text) || this.Config.tagregex.ifTagKeyTest.IsMatch(text)) { return; } TheMatch = regex.Match(text); if (TheMatch.Success) { this.Html = this.Html.Replace(origin, text); if (type == TagType._tag_list) { text = FindFirstListTagStr(text, this.TagList.Count()); } if (type == TagType._tag_command) { CMDTag tag = new CMDTag(text, origin, Deep, this.Config, this.TagList.Count); GetCMD(tag); this.TagList.Add(tag); } else if (type == TagType._tag_list) { if (this is SubListPage) { ListTag tag = new ListTag(text, origin, Deep, (this as SubListPage).PageName, this.Config, this.TagList.Count); this.TagList.Add(tag); } else { ListTag tag = new ListTag(text, origin, Deep, this is ItemPage ? (this as ItemPage).PageName : "", this.Config, this.TagList.Count); this.TagList.Add(tag); } } else if (type == TagType._tag_read) { ReadTag tag = new ReadTag(text, origin, Deep, this.Config, this.TagList.Count); this.TagList.Add(tag); } else if (type == TagType._tag_label) { LabelTag tag = new LabelTag(text, origin, Deep, this is LabelPage ? (this as LabelPage).PageName : "", this.Config, this.TagList.Count); tag.LazyLoad(); this.TagList.Add(tag); } else if (type == TagType._tag_static) { StaticTag tag = new StaticTag(text, origin, Deep, this is StaticPage ? (this as StaticPage).PageName : "", this.Config, this.TagList.Count); this.TagList.Add(tag); } else if (type == TagType._tag_filed) { FieldTag tag = new FieldTag(text, origin, Deep, this.Config, this.TagList.Count); this.TagList.Add(tag); } else if (type == TagType._tag_method) { MethodTag tag = new MethodTag(text, origin, Deep, this.Config, this.TagList.Count); this.TagList.Add(tag); } else if (type == TagType._tag_pager) { PagerTag tag = new PagerTag(text, origin, Deep, this.Config, this.TagList.Count); this.TagList.Add(tag); } else if (type == TagType._tag_form) { FormTag tag = new FormTag(text, origin, Deep, this.Config, this.TagList.Count); this.TagList.Add(tag); this.TagCallBack = "form"; } else if (type == TagType._tag_json) { JsonTag tag = new JsonTag(text, origin, Deep, this.Config, this.TagList.Count); this.TagList.Add(tag); this.TagCallBack = "json"; } } }