- 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/JSONString.cs
r309 r325 1 using System;2 1 using System.Text; 3 2 4 namespace AllocsFixes.JSON 5 { 6 public class JSONString : JSONValue 7 { 8 private string value; 3 namespace AllocsFixes.JSON { 4 public class JSONString : JSONValue { 5 private readonly string value; 9 6 10 public JSONString (string value) 11 { 7 public JSONString (string value) { 12 8 this.value = value; 13 9 } 14 10 15 public string GetString () 16 { 11 public string GetString () { 17 12 return value; 18 13 } 19 14 20 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 21 { 15 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) { 22 16 if (value == null || value.Length == 0) { 23 17 stringBuilder.Append ("\"\""); … … 27 21 int len = value.Length; 28 22 29 stringBuilder.EnsureCapacity (stringBuilder.Length + 2*len); 30 String t; 23 stringBuilder.EnsureCapacity (stringBuilder.Length + 2 * len); 31 24 32 25 stringBuilder.Append ('"'); … … 36 29 case '\\': 37 30 case '"': 31 38 32 // case '/': 39 33 stringBuilder.Append ('\\'); … … 58 52 if (c < ' ') { 59 53 stringBuilder.Append ("\\u"); 60 stringBuilder.Append (((int) c).ToString ("X4"));54 stringBuilder.Append (((int) c).ToString ("X4")); 61 55 } else { 62 56 stringBuilder.Append (c); 63 57 } 58 64 59 break; 65 60 } … … 69 64 } 70 65 71 public static JSONString Parse (string json, ref int offset) 72 { 66 public static JSONString Parse (string json, ref int offset) { 73 67 //Log.Out ("ParseString enter (" + offset + ")"); 74 68 StringBuilder sb = new StringBuilder (); … … 103 97 break; 104 98 } 99 105 100 offset++; 106 101 break; 107 102 case '"': 108 103 offset++; 104 109 105 //Log.Out ("JSON:Parsed String: " + sb.ToString ()); 110 106 return new JSONString (sb.ToString ()); … … 115 111 } 116 112 } 113 117 114 throw new MalformedJSONException ("End of JSON reached before parsing string finished"); 118 115 } 119 120 116 } 121 117 } 122
Note:
See TracChangeset
for help on using the changeset viewer.