| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 static final String TRUE_STRING = "true"; | 100 static final String TRUE_STRING = "true"; |
| 101 static final String FALSE_STRING = "false"; | 101 static final String FALSE_STRING = "false"; |
| 102 | 102 |
| 103 | 103 |
| 104 static parse(String json) { | 104 static parse(String json) { |
| 105 return new _JsonParser._internal(json)._parseToplevel(); | 105 return new _JsonParser._internal(json)._parseToplevel(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 static objectLength(String str) { | 108 static objectLength(String str) { |
| 109 var p = new _JsonParser._internal(str); | 109 var p = new _JsonParser._internal(str); |
| 110 var firstToken = p._token(); |
| 111 if (firstToken != LBRACE) { |
| 112 return 0; |
| 113 } |
| 110 try { | 114 try { |
| 111 p._parseObject(); | 115 p._parseObject(); |
| 112 assert(p.position <= p.length); | 116 assert(p.position <= p.length); |
| 113 return p.position; | 117 return p.position; |
| 114 } catch (var e) { | 118 } catch (var e) { |
| 115 return 0; | 119 return 0; |
| 116 } | 120 } |
| 117 } | 121 } |
| 118 | 122 |
| 119 _JsonParser._internal(String json) | 123 _JsonParser._internal(String json) |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 }); | 544 }); |
| 541 _sb.add('}'); | 545 _sb.add('}'); |
| 542 _seen.removeLast(); | 546 _seen.removeLast(); |
| 543 return; | 547 return; |
| 544 | 548 |
| 545 default: | 549 default: |
| 546 throw const JsonUnsupportedObjectType(); | 550 throw const JsonUnsupportedObjectType(); |
| 547 } | 551 } |
| 548 } | 552 } |
| 549 } | 553 } |
| OLD | NEW |