- Timestamp:
- Sep 3, 2014, 3:30:01 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/JSON/JSONString.cs
r154 r160 1 1 using System; 2 using System.Text; 2 3 3 4 namespace AllocsFixes.JSON … … 14 15 public override string ToString () 15 16 { 16 return string.Format ("\"{0}\"", value); 17 if (value == null || value.Length == 0) { 18 return ""; 19 } 20 21 int len = value.Length; 22 23 StringBuilder sb = new StringBuilder (len + 4); 24 String t; 25 26 foreach (char c in value) { 27 switch (c) { 28 case '\\': 29 case '"': 30 case '/': 31 sb.Append ('\\'); 32 sb.Append (c); 33 break; 34 case '\b': 35 sb.Append ("\\b"); 36 break; 37 case '\t': 38 sb.Append ("\\t"); 39 break; 40 case '\n': 41 sb.Append ("\\n"); 42 break; 43 case '\f': 44 sb.Append ("\\f"); 45 break; 46 case '\r': 47 sb.Append ("\\r"); 48 break; 49 default: 50 if (c < ' ') { 51 t = "000" + String.Format ("X", c); 52 sb.Append ("\\u" + t.Substring (t.Length - 4)); 53 } else { 54 sb.Append (c); 55 } 56 break; 57 } 58 } 59 60 return string.Format ("\"{0}\"", sb.ToString ()); 17 61 } 18 62
Note:
See TracChangeset
for help on using the changeset viewer.