| OLD | NEW |
| 1 part of dart.convert; | 1 part of dart.convert; |
| 2 class JsonUnsupportedObjectError extends Error {final unsupportedObject; | 2 class JsonUnsupportedObjectError extends Error {final unsupportedObject; |
| 3 final cause; | 3 final cause; |
| 4 JsonUnsupportedObjectError(this.unsupportedObject, { | 4 JsonUnsupportedObjectError(this.unsupportedObject, { |
| 5 this.cause} | 5 this.cause} |
| 6 ); | 6 ); |
| 7 String toString() { | 7 String toString() { |
| 8 if (cause != null) { | 8 if (cause != null) { |
| 9 return "Converting object to an encodable object failed."; | 9 return "Converting object to an encodable object failed."; |
| 10 } | 10 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 class JsonUtf8Encoder extends Converter<Object, List<int>> {static const int DE
FAULT_BUFFER_SIZE = 256; | 77 class JsonUtf8Encoder extends Converter<Object, List<int>> {static const int DE
FAULT_BUFFER_SIZE = 256; |
| 78 final List<int> _indent; | 78 final List<int> _indent; |
| 79 final Function _toEncodable; | 79 final Function _toEncodable; |
| 80 final int _bufferSize; | 80 final int _bufferSize; |
| 81 JsonUtf8Encoder([String indent, toEncodable(Object object), int bufferSize = DE
FAULT_BUFFER_SIZE]) : _indent = _utf8Encode(indent), _toEncodable = toEncodable,
_bufferSize = bufferSize; | 81 JsonUtf8Encoder([String indent, toEncodable(Object object), int bufferSize = DE
FAULT_BUFFER_SIZE]) : _indent = _utf8Encode(indent), _toEncodable = toEncodable,
_bufferSize = bufferSize; |
| 82 static List<int> _utf8Encode(String string) { | 82 static List<int> _utf8Encode(String string) { |
| 83 if (string == null) return null; | 83 if (string == null) return null; |
| 84 if (string.isEmpty) return new Uint8List(0); | 84 if (string.isEmpty) return new Uint8List(0); |
| 85 checkAscii: { | 85 checkAscii: { |
| 86 for (int i = 0; | 86 for (int i = 0; i < string.length; i++) { |
| 87 i < string.length; | |
| 88 i++) { | |
| 89 if (string.codeUnitAt(i) >= 0x80) break checkAscii; | 87 if (string.codeUnitAt(i) >= 0x80) break checkAscii; |
| 90 } | 88 } |
| 91 return string.codeUnits; | 89 return string.codeUnits; |
| 92 } | 90 } |
| 93 return UTF8.encode(string); | 91 return UTF8.encode(string); |
| 94 } | 92 } |
| 95 List<int> convert(Object object) { | 93 List<int> convert(Object object) { |
| 96 List<List<int>> bytes = ((__x10) => DDC$RT.cast(__x10, DDC$RT.type((List<dynamic
> _) { | 94 List<List<int>> bytes = ((__x10) => DDC$RT.cast(__x10, DDC$RT.type((List<dynamic
> _) { |
| 97 } | 95 } |
| 98 ), DDC$RT.type((List<List<int>> _) { | 96 ), DDC$RT.type((List<List<int>> _) { |
| 99 } | 97 } |
| 100 ), "CastLiteral", """line 338, column 29 of dart:convert/json.dart: """, __x10 i
s List<List<int>>, false))([]); | 98 ), "CastLiteral", """line 338, column 29 of dart:convert/json.dart: """, __x10 i
s List<List<int>>, false))([]); |
| 101 void addChunk(Uint8List chunk, int start, int end) { | 99 void addChunk(Uint8List chunk, int start, int end) { |
| 102 if (start > 0 || end < chunk.length) { | 100 if (start > 0 || end < chunk.length) { |
| 103 int length = end - start; | 101 int length = end - start; |
| 104 chunk = new Uint8List.view(chunk.buffer, chunk.offsetInBytes + start, length); | 102 chunk = new Uint8List.view(chunk.buffer, chunk.offsetInBytes + start, length); |
| 105 } | 103 } |
| 106 bytes.add(chunk); | 104 bytes.add(chunk); |
| 107 } | 105 } |
| 108 _JsonUtf8Stringifier.stringify(object, _indent, DDC$RT.cast(_toEncodable, Funct
ion, __t11, "CastGeneral", """line 352, column 36 of dart:convert/json.dart: """
, _toEncodable is __t11, false), _bufferSize, addChunk); | 106 _JsonUtf8Stringifier.stringify(object, _indent, DDC$RT.cast(_toEncodable, Funct
ion, __t11, "CastGeneral", """line 352, column 36 of dart:convert/json.dart: """
, _toEncodable is __t11, false), _bufferSize, addChunk); |
| 109 if (bytes.length == 1) return bytes[0]; | 107 if (bytes.length == 1) return bytes[0]; |
| 110 int length = 0; | 108 int length = 0; |
| 111 for (int i = 0; | 109 for (int i = 0; i < bytes.length; i++) { |
| 112 i < bytes.length; | |
| 113 i++) { | |
| 114 length += bytes[i].length; | 110 length += bytes[i].length; |
| 115 } | 111 } |
| 116 Uint8List result = new Uint8List(length); | 112 Uint8List result = new Uint8List(length); |
| 117 for (int i = 0, offset = 0; | 113 for (int i = 0, offset = 0; i < bytes.length; i++) { |
| 118 i < bytes.length; | |
| 119 i++) { | |
| 120 var byteList = bytes[i]; | 114 var byteList = bytes[i]; |
| 121 int end = offset + byteList.length; | 115 int end = offset + byteList.length; |
| 122 result.setRange(offset, end, byteList); | 116 result.setRange(offset, end, byteList); |
| 123 offset = end; | 117 offset = end; |
| 124 } | 118 } |
| 125 return result; | 119 return result; |
| 126 } | 120 } |
| 127 ChunkedConversionSink<Object> startChunkedConversion(Sink<List<int>> sink) { | 121 ChunkedConversionSink<Object> startChunkedConversion(Sink<List<int>> sink) { |
| 128 ByteConversionSink byteSink; | 122 ByteConversionSink byteSink; |
| 129 if (sink is ByteConversionSink) { | 123 if (sink is ByteConversionSink) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 final Function _toEncodable; | 210 final Function _toEncodable; |
| 217 _JsonStringifier(Object _toEncodable(Object o)) : _toEncodable = (_toEncodable
!= null) ? _toEncodable : _defaultToEncodable; | 211 _JsonStringifier(Object _toEncodable(Object o)) : _toEncodable = (_toEncodable
!= null) ? _toEncodable : _defaultToEncodable; |
| 218 void writeString(String characters); | 212 void writeString(String characters); |
| 219 void writeStringSlice(String characters, int start, int end); | 213 void writeStringSlice(String characters, int start, int end); |
| 220 void writeCharCode(int charCode); | 214 void writeCharCode(int charCode); |
| 221 void writeNumber(num number); | 215 void writeNumber(num number); |
| 222 static int hexDigit(int x) => x < 10 ? 48 + x : 87 + x; | 216 static int hexDigit(int x) => x < 10 ? 48 + x : 87 + x; |
| 223 void writeStringContent(String s) { | 217 void writeStringContent(String s) { |
| 224 int offset = 0; | 218 int offset = 0; |
| 225 final int length = s.length; | 219 final int length = s.length; |
| 226 for (int i = 0; | 220 for (int i = 0; i < length; i++) { |
| 227 i < length; | |
| 228 i++) { | |
| 229 int charCode = s.codeUnitAt(i); | 221 int charCode = s.codeUnitAt(i); |
| 230 if (charCode > BACKSLASH) continue; | 222 if (charCode > BACKSLASH) continue; |
| 231 if (charCode < 32) { | 223 if (charCode < 32) { |
| 232 if (i > offset) writeStringSlice(s, offset, i); | 224 if (i > offset) writeStringSlice(s, offset, i); |
| 233 offset = i + 1; | 225 offset = i + 1; |
| 234 writeCharCode(BACKSLASH); | 226 writeCharCode(BACKSLASH); |
| 235 switch (charCode) {case BACKSPACE: writeCharCode(CHAR_b); | 227 switch (charCode) {case BACKSPACE: writeCharCode(CHAR_b); |
| 236 break; | 228 break; |
| 237 case TAB: writeCharCode(CHAR_t); | 229 case TAB: writeCharCode(CHAR_t); |
| 238 break; | 230 break; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 258 } | 250 } |
| 259 } | 251 } |
| 260 if (offset == 0) { | 252 if (offset == 0) { |
| 261 writeString(s); | 253 writeString(s); |
| 262 } | 254 } |
| 263 else if (offset < length) { | 255 else if (offset < length) { |
| 264 writeStringSlice(s, offset, length); | 256 writeStringSlice(s, offset, length); |
| 265 } | 257 } |
| 266 } | 258 } |
| 267 void _checkCycle(object) { | 259 void _checkCycle(object) { |
| 268 for (int i = 0; | 260 for (int i = 0; i < _seen.length; i++) { |
| 269 i < _seen.length; | |
| 270 i++) { | |
| 271 if (identical(object, _seen[i])) { | 261 if (identical(object, _seen[i])) { |
| 272 throw new JsonCyclicError(object); | 262 throw new JsonCyclicError(object); |
| 273 } | 263 } |
| 274 } | 264 } |
| 275 _seen.add(object); | 265 _seen.add(object); |
| 276 } | 266 } |
| 277 void _removeSeen(object) { | 267 void _removeSeen(object) { |
| 278 assert (!_seen.isEmpty); assert (identical(_seen.last, object)); _seen.removeLas
t(); | 268 assert (!_seen.isEmpty); assert (identical(_seen.last, object)); _seen.removeLas
t(); |
| 279 } | 269 } |
| 280 void writeObject(object) { | 270 void writeObject(object) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 return true; | 321 return true; |
| 332 } | 322 } |
| 333 else { | 323 else { |
| 334 return false; | 324 return false; |
| 335 } | 325 } |
| 336 } | 326 } |
| 337 void writeList(List list) { | 327 void writeList(List list) { |
| 338 writeString('['); | 328 writeString('['); |
| 339 if (list.length > 0) { | 329 if (list.length > 0) { |
| 340 writeObject(list[0]); | 330 writeObject(list[0]); |
| 341 for (int i = 1; | 331 for (int i = 1; i < list.length; i++) { |
| 342 i < list.length; | |
| 343 i++) { | |
| 344 writeString(','); | 332 writeString(','); |
| 345 writeObject(list[i]); | 333 writeObject(list[i]); |
| 346 } | 334 } |
| 347 } | 335 } |
| 348 writeString(']'); | 336 writeString(']'); |
| 349 } | 337 } |
| 350 void writeMap(Map<String, Object> map) { | 338 void writeMap(Map<String, Object> map) { |
| 351 writeString('{'); | 339 writeString('{'); |
| 352 String separator = '"'; | 340 String separator = '"'; |
| 353 map.forEach((String key, value) { | 341 map.forEach((String key, value) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 365 void writeIndentation(indentLevel); | 353 void writeIndentation(indentLevel); |
| 366 void writeList(List list) { | 354 void writeList(List list) { |
| 367 if (list.isEmpty) { | 355 if (list.isEmpty) { |
| 368 writeString('[]'); | 356 writeString('[]'); |
| 369 } | 357 } |
| 370 else { | 358 else { |
| 371 writeString('[\n'); | 359 writeString('[\n'); |
| 372 _indentLevel++; | 360 _indentLevel++; |
| 373 writeIndentation(_indentLevel); | 361 writeIndentation(_indentLevel); |
| 374 writeObject(list[0]); | 362 writeObject(list[0]); |
| 375 for (int i = 1; | 363 for (int i = 1; i < list.length; i++) { |
| 376 i < list.length; | |
| 377 i++) { | |
| 378 writeString(',\n'); | 364 writeString(',\n'); |
| 379 writeIndentation(_indentLevel); | 365 writeIndentation(_indentLevel); |
| 380 writeObject(list[i]); | 366 writeObject(list[i]); |
| 381 } | 367 } |
| 382 writeString('\n'); | 368 writeString('\n'); |
| 383 _indentLevel--; | 369 _indentLevel--; |
| 384 writeIndentation(_indentLevel); | 370 writeIndentation(_indentLevel); |
| 385 writeString(']'); | 371 writeString(']'); |
| 386 } | 372 } |
| 387 } | 373 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 void writeStringSlice(String string, int start, int end) { | 428 void writeStringSlice(String string, int start, int end) { |
| 443 _sink.write(string.substring(start, end)); | 429 _sink.write(string.substring(start, end)); |
| 444 } | 430 } |
| 445 void writeCharCode(int charCode) { | 431 void writeCharCode(int charCode) { |
| 446 _sink.writeCharCode(charCode); | 432 _sink.writeCharCode(charCode); |
| 447 } | 433 } |
| 448 } | 434 } |
| 449 class _JsonStringStringifierPretty extends _JsonStringStringifier with _JsonPre
ttyPrintMixin {final String _indent; | 435 class _JsonStringStringifierPretty extends _JsonStringStringifier with _JsonPre
ttyPrintMixin {final String _indent; |
| 450 _JsonStringStringifierPretty(StringSink sink, Function toEncodable, this._inden
t) : super(sink, toEncodable); | 436 _JsonStringStringifierPretty(StringSink sink, Function toEncodable, this._inden
t) : super(sink, toEncodable); |
| 451 void writeIndentation(int count) { | 437 void writeIndentation(int count) { |
| 452 for (int i = 0; | 438 for (int i = 0; i < count; i++) writeString(_indent); |
| 453 i < count; | |
| 454 i++) writeString(_indent); | |
| 455 } | 439 } |
| 456 } | 440 } |
| 457 class _JsonUtf8Stringifier extends _JsonStringifier {final int bufferSize; | 441 class _JsonUtf8Stringifier extends _JsonStringifier {final int bufferSize; |
| 458 final Function addChunk; | 442 final Function addChunk; |
| 459 Uint8List buffer; | 443 Uint8List buffer; |
| 460 int index = 0; | 444 int index = 0; |
| 461 _JsonUtf8Stringifier(toEncodable, int bufferSize, this.addChunk) : super(DDC$RT
.cast(toEncodable, dynamic, __t24, "CastGeneral", """line 874, column 15 of dart
:convert/json.dart: """, toEncodable is __t24, false)), this.bufferSize = buffer
Size, buffer = new Uint8List(bufferSize); | 445 _JsonUtf8Stringifier(toEncodable, int bufferSize, this.addChunk) : super(DDC$RT
.cast(toEncodable, dynamic, __t24, "CastGeneral", """line 874, column 15 of dart
:convert/json.dart: """, toEncodable is __t24, false)), this.bufferSize = buffer
Size, buffer = new Uint8List(bufferSize); |
| 462 static void stringify(Object object, List<int> indent, toEncodableFunction(Obje
ct o), int bufferSize, void addChunk(Uint8List chunk, int start, int end)) { | 446 static void stringify(Object object, List<int> indent, toEncodableFunction(Obje
ct o), int bufferSize, void addChunk(Uint8List chunk, int start, int end)) { |
| 463 _JsonUtf8Stringifier stringifier; | 447 _JsonUtf8Stringifier stringifier; |
| 464 if (indent != null) { | 448 if (indent != null) { |
| 465 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent, buffer
Size, addChunk); | 449 stringifier = new _JsonUtf8StringifierPretty(toEncodableFunction, indent, buffer
Size, addChunk); |
| 466 } | 450 } |
| 467 else { | 451 else { |
| 468 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize, addChunk
); | 452 stringifier = new _JsonUtf8Stringifier(toEncodableFunction, bufferSize, addChunk
); |
| 469 } | 453 } |
| 470 stringifier.writeObject(object); | 454 stringifier.writeObject(object); |
| 471 stringifier.flush(); | 455 stringifier.flush(); |
| 472 } | 456 } |
| 473 void flush() { | 457 void flush() { |
| 474 if (index > 0) { | 458 if (index > 0) { |
| 475 addChunk(buffer, 0, index); | 459 addChunk(buffer, 0, index); |
| 476 } | 460 } |
| 477 buffer = null; | 461 buffer = null; |
| 478 index = 0; | 462 index = 0; |
| 479 } | 463 } |
| 480 void writeNumber(num number) { | 464 void writeNumber(num number) { |
| 481 writeAsciiString(number.toString()); | 465 writeAsciiString(number.toString()); |
| 482 } | 466 } |
| 483 void writeAsciiString(String string) { | 467 void writeAsciiString(String string) { |
| 484 for (int i = 0; | 468 for (int i = 0; i < string.length; i++) { |
| 485 i < string.length; | |
| 486 i++) { | |
| 487 int char = string.codeUnitAt(i); | 469 int char = string.codeUnitAt(i); |
| 488 assert (char <= 0x7f); writeByte(char); | 470 assert (char <= 0x7f); writeByte(char); |
| 489 } | 471 } |
| 490 } | 472 } |
| 491 void writeString(String string) { | 473 void writeString(String string) { |
| 492 writeStringSlice(string, 0, string.length); | 474 writeStringSlice(string, 0, string.length); |
| 493 } | 475 } |
| 494 void writeStringSlice(String string, int start, int end) { | 476 void writeStringSlice(String string, int start, int end) { |
| 495 for (int i = start; | 477 for (int i = start; i < end; i++) { |
| 496 i < end; | |
| 497 i++) { | |
| 498 int char = string.codeUnitAt(i); | 478 int char = string.codeUnitAt(i); |
| 499 if (char <= 0x7f) { | 479 if (char <= 0x7f) { |
| 500 writeByte(char); | 480 writeByte(char); |
| 501 } | 481 } |
| 502 else { | 482 else { |
| 503 if ((char & 0xFC00) == 0xD800 && i + 1 < end) { | 483 if ((char & 0xFC00) == 0xD800 && i + 1 < end) { |
| 504 int nextChar = string.codeUnitAt(i + 1); | 484 int nextChar = string.codeUnitAt(i + 1); |
| 505 if ((nextChar & 0xFC00) == 0xDC00) { | 485 if ((nextChar & 0xFC00) == 0xDC00) { |
| 506 char = 0x10000 + ((char & 0x3ff) << 10) + (nextChar & 0x3ff); | 486 char = 0x10000 + ((char & 0x3ff) << 10) + (nextChar & 0x3ff); |
| 507 writeFourByteCharCode(char); | 487 writeFourByteCharCode(char); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 } | 539 } |
| 560 return;} | 540 return;} |
| 561 while (count > 0) { | 541 while (count > 0) { |
| 562 count--; | 542 count--; |
| 563 int end = index + indentLength; | 543 int end = index + indentLength; |
| 564 if (end <= buffer.length) { | 544 if (end <= buffer.length) { |
| 565 buffer.setRange(index, end, indent); | 545 buffer.setRange(index, end, indent); |
| 566 index = end; | 546 index = end; |
| 567 } | 547 } |
| 568 else { | 548 else { |
| 569 for (int i = 0; | 549 for (int i = 0; i < indentLength; i++) { |
| 570 i < indentLength; | |
| 571 i++) { | |
| 572 writeByte(indent[i]); | 550 writeByte(indent[i]); |
| 573 } | 551 } |
| 574 } | 552 } |
| 575 } | 553 } |
| 576 } | 554 } |
| 577 } | 555 } |
| 578 typedef dynamic __t7(dynamic __u8); | 556 typedef dynamic __t7(dynamic __u8); |
| 579 typedef dynamic __t11(Object __u12); | 557 typedef dynamic __t11(Object __u12); |
| 580 typedef void __t17(dynamic __u18, dynamic __u19); | 558 typedef void __t17(dynamic __u18, dynamic __u19); |
| 581 typedef dynamic __t20(String __u21, Object __u22); | 559 typedef dynamic __t20(String __u21, Object __u22); |
| 582 typedef Object __t24(Object __u25); | 560 typedef Object __t24(Object __u25); |
| OLD | NEW |