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 part of common; | 5 part of common; |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 num get number { | 55 num get number { |
56 assert(kind == NUMBER); | 56 assert(kind == NUMBER); |
57 return _n; | 57 return _n; |
58 } | 58 } |
59 | 59 |
60 const JsonToken._internal(this.kind, this._s, this._n); | 60 const JsonToken._internal(this.kind, this._s, this._n); |
61 | 61 |
62 factory JsonToken.string(String s) { | 62 factory JsonToken.string(String s) { |
63 return new JsonToken._internal(STRING, s, 0); | 63 return new JsonToken._internal(STRING, s, 0); |
64 } | 64 } |
65 factory JsonToken.number(num n) { | 65 factory JsonToken.numberItem(num n) { |
66 return new JsonToken._internal(NUMBER, '', n); | 66 return new JsonToken._internal(NUMBER, '', n); |
67 } | 67 } |
68 factory JsonToken.atom(int kind) { | 68 factory JsonToken.atom(int kind) { |
69 return new JsonToken._internal(kind, '', 0); | 69 return new JsonToken._internal(kind, '', 0); |
70 } | 70 } |
71 | 71 |
72 String toString() { | 72 String toString() { |
73 switch (kind) { | 73 switch (kind) { |
74 case STRING: | 74 case STRING: |
75 return 'STRING(${_s})'; | 75 return 'STRING(${_s})'; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 isInteger = false; | 246 isInteger = false; |
247 _pos++; | 247 _pos++; |
248 c = _s.charCodeAt(_pos); | 248 c = _s.charCodeAt(_pos); |
249 if (c == PLUS || c == MINUS) { | 249 if (c == PLUS || c == MINUS) { |
250 _pos++; | 250 _pos++; |
251 } | 251 } |
252 skipDigits(); | 252 skipDigits(); |
253 } | 253 } |
254 | 254 |
255 final String body = _s.substring(startPos, _pos); | 255 final String body = _s.substring(startPos, _pos); |
256 return new JsonToken.number( | 256 return new JsonToken.numberItem( |
257 isInteger ? int.parse(body) : double.parse(body)); | 257 isInteger ? int.parse(body) : double.parse(body)); |
258 | 258 |
259 case cur == LBRACE: | 259 case cur == LBRACE: |
260 _pos++; | 260 _pos++; |
261 return new JsonToken.atom(JsonToken.LBRACE); | 261 return new JsonToken.atom(JsonToken.LBRACE); |
262 | 262 |
263 case cur == RBRACE: | 263 case cur == RBRACE: |
264 _pos++; | 264 _pos++; |
265 return new JsonToken.atom(JsonToken.RBRACE); | 265 return new JsonToken.atom(JsonToken.RBRACE); |
266 | 266 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 _sb.add(','); | 562 _sb.add(','); |
563 } | 563 } |
564 }); | 564 }); |
565 _sb.add('}'); | 565 _sb.add('}'); |
566 return; | 566 return; |
567 } else { | 567 } else { |
568 throw const JsonUnsupportedObjectType(); | 568 throw const JsonUnsupportedObjectType(); |
569 } | 569 } |
570 } | 570 } |
571 } | 571 } |
OLD | NEW |