/// <summary> /// 预处理节点代码 /// </summary> /// <param name="nodeCode"></param> /// <param name="name"></param> /// <param name="value"></param> private static NameAndValue PreHandle(CodeType parentCodeType, StringSegment nodeCode) { StringSegment name, value; var code = nodeCode.Trim(); if (CodeTreeNode.IsObject(code) || CodeTreeNode.IsList(code)) { name = StringSegment.Null; value = code; } else { var info = DeserializerUtil.Find(code, 0, ':'); if (parentCodeType == CodeType.Object) { name = !info.Finded ? code : code.Substring(0, info.KeyPosition).Trim(); value = !info.Finded ? StringSegment.Null : code.Substring(info.KeyPosition + 1).Trim(); } else { name = !info.Finded ? StringSegment.Null : code.Substring(0, info.KeyPosition).Trim(); value = !info.Finded ? code : code.Substring(info.KeyPosition + 1).Trim(); } } return new NameAndValue(name, value); }
private static CodeTreeNode[] ParseNodes(CodeType parentCodeType, StringSegment code) { CodeTreeNode[] result = null; using (var temp = _nodesPool.Borrow()) { List <CodeTreeNode> nodes = temp.Item; int startIndex = 0; var info = DeserializerUtil.Find(code, startIndex, ','); while (!info.IsEmpty()) { nodes.Add(ParseNode(parentCodeType, info.Pass)); info = DeserializerUtil.Find(code, info.KeyPosition + 1, ','); } result = nodes.ToArray(); } return(result); }