protected void BlockEndXML(JsonNode o, ref StringBuilder retVal, String newLine) { if (o.Tag != JsonTag.JSON_OBJECT && o.Tag != JsonTag.JSON_ARRAY) { return; } if (m_Indent > -1) { m_Indent -= m_Shift_Width; if (m_Indent > 0) { retVal.Append(' ', m_Indent); } } if (o.HasKey) { retVal.Append("</").Append(o.Key(src)).Append('>').Append(newLine); } else { int no = nos.Count - 1; retVal.Append("</No").Append(nos[no]++).Append('>').Append(newLine); if (null == o.NodeBelow.NextTo) { nos[no] = 1; } } }
public StringBuilder DumpXMLValueIterative(JsonNode o) { JsonNode startNode = o; String newLine; StringBuilder retVal = new StringBuilder(); if (m_Indent > -1) { newLine = "\n"; m_Indent = 0; } else { newLine = ""; } JsonTag startTag; nos = new List <int>(); do { if (m_Indent > -1) { retVal.Append(' ', m_Indent); // Start with m_Indent } startTag = o.Tag; if (startTag == JsonTag.JSON_OBJECT || startTag == JsonTag.JSON_ARRAY) { String open = ""; if (startTag == JsonTag.JSON_ARRAY) { open = "<EmptyArray></EmptyArray>"; } else { open = "<EmptyObject></EmptyObject>"; } if (o.ToNode() == null) { if (o.HasKey) { retVal.Append('<').Append(o.Key(src)).Append('>'); } if (o.NodeBelow.NextTo == null) { retVal.Append(open); } else { retVal.Append(open).Append(newLine); } if (o.HasKey) { retVal.Append("</").Append(o.Key(src)).Append(">"); } if (o.NodeBelow.NextTo == null) { retVal.Append(newLine); } if (o.NodeBelow.NextTo == null) { o = o.NodeBelow; } } else { if (o.HasKey) { retVal.Append('<').Append(o.Key(src)).Append(">"); } else { if (startNode == o) { nos.Add(1); retVal.Append("<ROOT>"); } else { retVal.Append("<No").Append(nos[nos.Count - 1]).Append('>'); } while (nos.Count < levelStack.Count) { nos.Add(1); } } if (o.ToNode() != null) { retVal.Append(newLine); } if (o.ToNode() == null && o.NodeBelow.NextTo != null) { BlockEndXML(o, ref retVal, newLine); } if (m_Indent > -1) { m_Indent += m_Shift_Width; } } } else if (startTag == JsonTag.JSON_STRING || startTag == JsonTag.JSON_NUMBER || startTag == JsonTag.JSON_NUMBER_STR) { String quote = (startTag == JsonTag.JSON_STRING) ? "\"" : ""; if (o.HasKey) { retVal.Append('<').Append(o.Key(src)).Append('>').Append(o.ToString(src)).Append("</").Append(o.Key(src)).Append('>').Append(newLine); // "key": "value"(,) } else { retVal.Append(quote).Append(o.ToString(src)).Append(quote).Append($"{(o.NodeBelow.NextTo != null ? "," : "")}{newLine}"); // "value"(,) } } else if (startTag == JsonTag.JSON_TRUE || startTag == JsonTag.JSON_FALSE || startTag == JsonTag.JSON_NULL) { String word; if (startTag == JsonTag.JSON_TRUE) { word = "true"; } else if (startTag == JsonTag.JSON_FALSE) { word = "false"; } else { word = "null"; } if (o.HasKey) { retVal.Append('<').Append(o.Key(src)).Append('>').Append(word).Append("</").Append(o.Key(src)).Append('>').Append(newLine); // "key": "value"(,) } else { retVal.Append(word).Append($"{(o.NodeBelow.NextTo != null ? "," : "")}{newLine}"); // "value"(,) } } if (o != null) { if (o.NodeBelow != null && (startTag == JsonTag.JSON_ARRAY || startTag == JsonTag.JSON_OBJECT)) { // move down 2 node of structured object levelStack.Push(o); o = o.NodeBelow; } else // move right to values { if (o.NodeBelow.NextTo != null) { o = o.NodeBelow.NextTo; } else { o = o.NodeBelow; // always null (4 null || non-structured) } } } while (o == null && levelStack.Count > 0) { // return back after iterations do { o = levelStack.Pop(); if (o.Tag == JsonTag.JSON_ARRAY || o.Tag == JsonTag.JSON_OBJECT) { // Array / Object end markers if (o == startNode) { return(retVal.Append("</ROOT>")); } else { BlockEndXML(o, ref retVal, newLine); } } } while ((levelStack.Count > 1) && ((o == null || (o.NodeBelow.NextTo == null && (o.NodeBelow == null || o.NodeBelow?.NodeBelow?.NextTo == null))))); o = o.NodeBelow.NextTo; // move right } if (o == startNode) { if (m_Indent > -1) { m_Indent = 0; } return(retVal.Append("\n... cycle here")); } } while (o != null || (levelStack.Count > 0)); return(retVal); }
public String DumpValueIterative(JsonNode o, Boolean debugModeLimit) { JsonNode startNode = o; String space, newLine, retVal = ""; if (m_Indent > -1) { space = " "; newLine = "\n"; } else { space = ""; newLine = ""; } JsonTag startTag; do { if (debugModeLimit && retVal.Length > m_debugModeLimit) { if (m_Indent > -1) { m_Indent = 0; } return(retVal + "\n..."); } if (m_Indent > -1) { retVal += (new String(' ', m_Indent)); // Start with m_Indent } startTag = o.Tag; if (startTag == JsonTag.JSON_OBJECT || startTag == JsonTag.JSON_ARRAY) { String open = ""; if (startTag == JsonTag.JSON_ARRAY) { open = "[]"; } else { open = "{}"; } if (o.ToNode() == null) { if (o.HasKey) { retVal += ($"\"{o.Key(src)}\":{space}"); // [] or key: [] } if (o.NextTo == null) { retVal += ($"{open}{newLine}"); } else { retVal += ($"{open},{newLine}"); } if (o.NextTo == null) { o = o.NodeBelow; } } else { open = open.Substring(0, 1); if (o.HasKey) { retVal += ($"\"{o.Key(src)}\":{space}{open}"); } else { retVal += ($"{open}"); } if (o.ToNode() != null) { retVal += (newLine); } if (o.ToNode() == null && o.NextTo != null) { BlockEnd(o, ref retVal, newLine); } if (m_Indent > -1) { m_Indent += m_Shift_Width; } } } else if (startTag == JsonTag.JSON_STRING || startTag == JsonTag.JSON_NUMBER || startTag == JsonTag.JSON_NUMBER_STR) { String quote = (startTag == JsonTag.JSON_STRING) ? "\"" : ""; if (o.HasKey) { retVal += ($"\"{o.Key(src)}\":{space}{quote}{o.ToString(src)}{quote}{(o.NextTo != null ? "," : "")}{newLine}"); // "key": "value"(,) } else { retVal += ($"{quote}{o.ToString(src)}{quote}{(o.NextTo != null ? "," : "")}{newLine}"); // "value"(,) } } else if (startTag == JsonTag.JSON_TRUE || startTag == JsonTag.JSON_FALSE || startTag == JsonTag.JSON_NULL) { String word; if (startTag == JsonTag.JSON_TRUE) { word = "true"; } else if (startTag == JsonTag.JSON_FALSE) { word = "false"; } else { word = "null"; } if (o.HasKey) { retVal += ($"\"{o.Key(src)}\":{space}{word}{(o.NextTo != null ? "," : "")}{newLine}"); // "key": "value"(,) } else { retVal += ($"{word}{(o.NextTo != null ? "," : "")}{newLine}"); // "value"(,) } } if (o != null) { if (o.NodeBelow != null && (startTag == JsonTag.JSON_ARRAY || startTag == JsonTag.JSON_OBJECT)) { // move down 2 node of structured object levelStack.Push(o); o = o.NodeBelow; } else // move right to values { if (o.NextTo != null) { o = o.NextTo; } else { o = o.NodeBelow; // always null (4 null || non-structured) } } } while (o == null && levelStack.Count > 0) { // return back after iterations do { o = levelStack.Pop(); if (o.Tag == JsonTag.JSON_ARRAY || o.Tag == JsonTag.JSON_OBJECT) { // Array / Object end markers BlockEnd(o, ref retVal, newLine); } else { BlockEnd(o, ref retVal, newLine); // Array / Object end markers } } while ((levelStack.Count > 1) && ((o == null || (o.NextTo == null && (o.NodeBelow == null || o.NodeBelow.NextTo == null))))); o = o.NextTo; // move right } if (o == startNode) { if (m_Indent > -1) { m_Indent = 0; } return(retVal + "\n... cycle here"); } } while (o != null || (levelStack.Count > 0)); return(retVal); }
public void DumpValueIterative(StreamWriter print2, JsonNode o, Byte[] src, int indent = 0) { String space, newLine; if (indent > -1) { space = " "; newLine = "\n"; } else { space = ""; newLine = ""; } JsonTag startTag; do { #if DEBUGGING VisualNode3 oV = new VisualNode3(ref o, src, 10000); #endif if (indent > -1) { print2.Write(new String(' ', indent)); // Start with indent } startTag = o.Tag; if (startTag == JsonTag.JSON_OBJECT || startTag == JsonTag.JSON_ARRAY) { String open = ""; if (startTag == JsonTag.JSON_ARRAY) { open = "[]"; } else { open = "{}"; } if (o.ToNode() == null) { if (o.HasKey) { print2.Write($"\"{o.Key(src)}\":{space}"); // [] or key: [] } if (o.next == null) { print2.Write($"{open}{newLine}"); } else { print2.Write($"{open},{newLine}"); } if (o.next == null) { o = o.node; } } else { open = open.Substring(0, 1); if (o.HasKey) { print2.Write($"\"{o.Key(src)}\":{space}{open}"); } else { print2.Write($"{open}"); } if (o.ToNode() != null) { print2.Write(newLine); } if (o.ToNode() == null && o.next != null) { BlockEnd(print2, o, ref indent, newLine); } if (indent > -1) { indent += SHIFT_WIDTH; } } } else if (startTag == JsonTag.JSON_STRING || startTag == JsonTag.JSON_NUMBER || startTag == JsonTag.JSON_NUMBER_STR) { String quote = (startTag == JsonTag.JSON_STRING) ? "\"" : ""; if (o.HasKey) { print2.Write($"\"{o.Key(src)}\":{space}{quote}{o.ToString(src)}{quote}{(o.next!=null?",":"")}{newLine}"); // "key": "value"(,) } else { print2.Write($"{quote}{o.ToString(src)}{quote}{(o.next!=null?",":"")}{newLine}"); // "value"(,) } } else if (startTag == JsonTag.JSON_TRUE || startTag == JsonTag.JSON_FALSE || startTag == JsonTag.JSON_NULL) { String word; if (startTag == JsonTag.JSON_TRUE) { word = "true"; } else if (startTag == JsonTag.JSON_FALSE) { word = "false"; } else { word = "null"; } if (o.HasKey) { print2.Write($"\"{o.Key(src)}\":{space}{word}{(o.next!=null?",":"")}{newLine}"); // "key": "value"(,) } else { print2.Write($"{word}{(o.next!=null?",":"")}{newLine}"); // "value"(,) } } if (o != null) { if (o.node != null && (startTag == JsonTag.JSON_ARRAY || startTag == JsonTag.JSON_OBJECT)) { // move down 2 node of structured object #if DEBUGGING levelStack.Push(new VisualNode3(ref o, src, 1000)); #else levelStack.Push(o); #endif o = o.node; } else // move right to values { if (o.next != null) { o = o.next; } else { o = o.node; // always null (4 null || non-structured) } } } while (o == null && levelStack.Count > 0) { // return back after iterations do { #if DEBUGGING o = levelStack.Pop().m_JsonNode; oV.ChangeNode(o); #else o = levelStack.Pop(); #endif if (o.Tag == JsonTag.JSON_ARRAY || o.Tag == JsonTag.JSON_OBJECT) { // Array / Object end markers BlockEnd(print2, o, ref indent, newLine); } else { BlockEnd(print2, o, ref indent, newLine); // Array / Object end markers } } while ((levelStack.Count > 1) && ((o == null || (o.next == null && (o.node == null || o.node.next == null))))); o = o.next; // move right } } while (o != null || (levelStack.Count > 0)); }