- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/JSON/JSONArray.cs
r315 r325 1 using System;2 1 using System.Collections.Generic; 3 2 using System.Text; 4 3 5 namespace AllocsFixes.JSON 6 { 7 public class JSONArray : JSONNode 8 { 9 private List<JSONNode> nodes = new List<JSONNode> (); 4 namespace AllocsFixes.JSON { 5 public class JSONArray : JSONNode { 6 private readonly List<JSONNode> nodes = new List<JSONNode> (); 10 7 11 8 public JSONNode this [int index] { … … 18 15 } 19 16 20 public void Add (JSONNode node) 21 { 17 public void Add (JSONNode node) { 22 18 nodes.Add (node); 23 19 } 24 20 25 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 26 { 21 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 27 22 stringBuilder.Append ("["); 28 if (prettyPrint) 23 if (prettyPrint) { 29 24 stringBuilder.Append ('\n'); 25 } 26 30 27 foreach (JSONNode n in nodes) { 31 if (prettyPrint) 32 stringBuilder.Append (new String ('\t', currentLevel + 1)); 28 if (prettyPrint) { 29 stringBuilder.Append (new string ('\t', currentLevel + 1)); 30 } 31 33 32 n.ToString (stringBuilder, prettyPrint, currentLevel + 1); 34 33 stringBuilder.Append (","); 35 if (prettyPrint) 34 if (prettyPrint) { 36 35 stringBuilder.Append ('\n'); 36 } 37 37 } 38 if (nodes.Count > 0) 38 39 if (nodes.Count > 0) { 39 40 stringBuilder.Remove (stringBuilder.Length - (prettyPrint ? 2 : 1), 1); 40 if (prettyPrint) 41 stringBuilder.Append (new String ('\t', currentLevel)); 41 } 42 43 if (prettyPrint) { 44 stringBuilder.Append (new string ('\t', currentLevel)); 45 } 46 42 47 stringBuilder.Append ("]"); 43 48 } 44 49 45 public static JSONArray Parse (string json, ref int offset) 46 { 50 public static JSONArray Parse (string json, ref int offset) { 47 51 //Log.Out ("ParseArray enter (" + offset + ")"); 48 52 JSONArray arr = new JSONArray (); … … 58 62 nextElemAllowed = true; 59 63 offset++; 60 } else 61 throw new MalformedJSONException ("Could not parse array, found a comma without a value first"); 64 } else { 65 throw new MalformedJSONException ( 66 "Could not parse array, found a comma without a value first"); 67 } 68 62 69 break; 63 70 case ']': 64 71 offset++; 72 65 73 //Log.Out ("JSON:Parsed Array: " + arr.ToString ()); 66 74 return arr; … … 72 80 } 73 81 } 74 75 82 } 76 83 } 77
Note:
See TracChangeset
for help on using the changeset viewer.