OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library("json"); | 5 #library("json"); |
6 | 6 |
7 // Pure Dart implementation of JSON protocol. | 7 // Pure Dart implementation of JSON protocol. |
8 | 8 |
9 /** | 9 /** |
10 * Utility class to parse JSON and serialize objects to JSON. | 10 * Utility class to parse JSON and serialize objects to JSON. |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 final int length = s.length; | 506 final int length = s.length; |
507 bool needsEscape = false; | 507 bool needsEscape = false; |
508 final charCodes = new List<int>(); | 508 final charCodes = new List<int>(); |
509 for (int i = 0; i < length; i++) { | 509 for (int i = 0; i < length; i++) { |
510 int charCode = s.charCodeAt(i); | 510 int charCode = s.charCodeAt(i); |
511 if (_needsEscape(charCode)) { | 511 if (_needsEscape(charCode)) { |
512 charCodes.add(JsonTokenizer.BACKSLASH); | 512 charCodes.add(JsonTokenizer.BACKSLASH); |
513 needsEscape = true; | 513 needsEscape = true; |
514 | 514 |
515 if (JsonTokenizer.NEW_LINE == charCode) { | 515 if (JsonTokenizer.NEW_LINE == charCode) { |
516 charCode = N_SMALL; | 516 charCode = JsonTokenizer.N_SMALL; |
517 } else if (JsonTokenizer.LINE_FEED == charCode) { | 517 } else if (JsonTokenizer.LINE_FEED == charCode) { |
518 charCode = R_SMALL; | 518 charCode = JsonTokenizer.R_SMALL; |
519 } | 519 } |
520 } | 520 } |
521 charCodes.add(charCode); | 521 charCodes.add(charCode); |
522 } | 522 } |
523 sb.add(needsEscape ? new String.fromCharCodes(charCodes) : s); | 523 sb.add(needsEscape ? new String.fromCharCodes(charCodes) : s); |
524 } | 524 } |
525 | 525 |
526 void _checkCycle(final object) { | 526 void _checkCycle(final object) { |
527 // TODO: use Iterables. | 527 // TODO: use Iterables. |
528 for (int i = 0; i < _seen.length; i++) { | 528 for (int i = 0; i < _seen.length; i++) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 }); | 592 }); |
593 _sb.add('}'); | 593 _sb.add('}'); |
594 _seen.removeLast(); | 594 _seen.removeLast(); |
595 return; | 595 return; |
596 | 596 |
597 default: | 597 default: |
598 throw const JsonUnsupportedObjectType(); | 598 throw const JsonUnsupportedObjectType(); |
599 } | 599 } |
600 } | 600 } |
601 } | 601 } |
OLD | NEW |