- Timestamp:
- Jan 19, 2019, 6:12:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/JSON/JSONString.cs
r325 r351 5 5 private readonly string value; 6 6 7 public JSONString (string value) {8 this.value =value;7 public JSONString (string _value) { 8 value = _value; 9 9 } 10 10 … … 13 13 } 14 14 15 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {15 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 16 16 if (value == null || value.Length == 0) { 17 stringBuilder.Append ("\"\"");17 _stringBuilder.Append ("\"\""); 18 18 return; 19 19 } … … 21 21 int len = value.Length; 22 22 23 stringBuilder.EnsureCapacity (stringBuilder.Length + 2 * len);23 _stringBuilder.EnsureCapacity (_stringBuilder.Length + 2 * len); 24 24 25 stringBuilder.Append ('"');25 _stringBuilder.Append ('"'); 26 26 27 27 foreach (char c in value) { … … 31 31 32 32 // case '/': 33 stringBuilder.Append ('\\');34 stringBuilder.Append (c);33 _stringBuilder.Append ('\\'); 34 _stringBuilder.Append (c); 35 35 break; 36 36 case '\b': 37 stringBuilder.Append ("\\b");37 _stringBuilder.Append ("\\b"); 38 38 break; 39 39 case '\t': 40 stringBuilder.Append ("\\t");40 _stringBuilder.Append ("\\t"); 41 41 break; 42 42 case '\n': 43 stringBuilder.Append ("\\n");43 _stringBuilder.Append ("\\n"); 44 44 break; 45 45 case '\f': 46 stringBuilder.Append ("\\f");46 _stringBuilder.Append ("\\f"); 47 47 break; 48 48 case '\r': 49 stringBuilder.Append ("\\r");49 _stringBuilder.Append ("\\r"); 50 50 break; 51 51 default: 52 52 if (c < ' ') { 53 stringBuilder.Append ("\\u");54 stringBuilder.Append (((int) c).ToString ("X4"));53 _stringBuilder.Append ("\\u"); 54 _stringBuilder.Append (((int) c).ToString ("X4")); 55 55 } else { 56 stringBuilder.Append (c);56 _stringBuilder.Append (c); 57 57 } 58 58 … … 61 61 } 62 62 63 stringBuilder.Append ('"');63 _stringBuilder.Append ('"'); 64 64 } 65 65 66 public static JSONString Parse (string json, ref intoffset) {66 public static JSONString Parse (string _json, ref int _offset) { 67 67 //Log.Out ("ParseString enter (" + offset + ")"); 68 68 StringBuilder sb = new StringBuilder (); 69 offset++;70 while ( offset <json.Length) {71 switch ( json [offset]) {69 _offset++; 70 while (_offset < _json.Length) { 71 switch (_json [_offset]) { 72 72 case '\\': 73 offset++;74 switch ( json [offset]) {73 _offset++; 74 switch (_json [_offset]) { 75 75 case '\\': 76 76 case '"': 77 77 case '/': 78 sb.Append ( json [offset]);78 sb.Append (_json [_offset]); 79 79 break; 80 80 case 'b': … … 94 94 break; 95 95 default: 96 sb.Append ( json [offset]);96 sb.Append (_json [_offset]); 97 97 break; 98 98 } 99 99 100 offset++;100 _offset++; 101 101 break; 102 102 case '"': 103 offset++;103 _offset++; 104 104 105 105 //Log.Out ("JSON:Parsed String: " + sb.ToString ()); 106 106 return new JSONString (sb.ToString ()); 107 107 default: 108 sb.Append ( json [offset]);109 offset++;108 sb.Append (_json [_offset]); 109 _offset++; 110 110 break; 111 111 }
Note:
See TracChangeset
for help on using the changeset viewer.