- Timestamp:
- Aug 9, 2017, 7:43:07 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/JSON/JSONString.cs
r306 r309 18 18 } 19 19 20 public override string ToString (bool prettyPrint = false, int currentLevel = 0)20 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) 21 21 { 22 22 if (value == null || value.Length == 0) { 23 return "\"\""; 23 stringBuilder.Append ("\"\""); 24 return; 24 25 } 25 26 26 27 int len = value.Length; 27 28 28 StringBuilder sb = new StringBuilder (len + 4);29 stringBuilder.EnsureCapacity (stringBuilder.Length + 2*len); 29 30 String t; 31 32 stringBuilder.Append ('"'); 30 33 31 34 foreach (char c in value) { … … 34 37 case '"': 35 38 // case '/': 36 s b.Append ('\\');37 s b.Append (c);39 stringBuilder.Append ('\\'); 40 stringBuilder.Append (c); 38 41 break; 39 42 case '\b': 40 s b.Append ("\\b");43 stringBuilder.Append ("\\b"); 41 44 break; 42 45 case '\t': 43 s b.Append ("\\t");46 stringBuilder.Append ("\\t"); 44 47 break; 45 48 case '\n': 46 s b.Append ("\\n");49 stringBuilder.Append ("\\n"); 47 50 break; 48 51 case '\f': 49 s b.Append ("\\f");52 stringBuilder.Append ("\\f"); 50 53 break; 51 54 case '\r': 52 s b.Append ("\\r");55 stringBuilder.Append ("\\r"); 53 56 break; 54 57 default: 55 58 if (c < ' ') { 56 t = "000" + String.Format ("X", c);57 s b.Append ("\\u" + t.Substring (t.Length - 4));59 stringBuilder.Append ("\\u"); 60 stringBuilder.Append (((int)c).ToString ("X4")); 58 61 } else { 59 s b.Append (c);62 stringBuilder.Append (c); 60 63 } 61 64 break; … … 63 66 } 64 67 65 return string.Format ("\"{0}\"", sb.ToString ());68 stringBuilder.Append ('"'); 66 69 } 67 70
Note:
See TracChangeset
for help on using the changeset viewer.