Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 | 89 |
| 90 static final String NULL_STRING = "null"; | 90 static final String NULL_STRING = "null"; |
| 91 static final String TRUE_STRING = "true"; | 91 static final String TRUE_STRING = "true"; |
| 92 static final String FALSE_STRING = "false"; | 92 static final String FALSE_STRING = "false"; |
| 93 | 93 |
| 94 | 94 |
| 95 static parse(String json) { | 95 static parse(String json) { |
| 96 return new _JsonParser._internal(json)._parseToplevel(); | 96 return new _JsonParser._internal(json)._parseToplevel(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 _JsonParser._internal(String this.json) { | 99 _JsonParser._internal(String json) : this.json = '${json} ' { |
|
Anders Johnsen
2012/04/28 08:23:22
This is not the correct way to fix this. This will
Anton Muhin
2012/04/28 08:25:07
I didn't do performance measurements, I'd prefer i
Anders Johnsen
2012/04/28 09:03:07
Agreed! I'll fix the number parsing error in anoth
| |
| 100 if (tokens !== null) return; | 100 if (tokens !== null) return; |
| 101 | 101 |
| 102 // Use a list as jump-table, faster then switch and if. | 102 // Use a list as jump-table, faster then switch and if. |
| 103 tokens = new List<int>(LAST_ASCII + 1); | 103 tokens = new List<int>(LAST_ASCII + 1); |
| 104 tokens[TAB] = WHITESPACE; | 104 tokens[TAB] = WHITESPACE; |
| 105 tokens[NEW_LINE] = WHITESPACE; | 105 tokens[NEW_LINE] = WHITESPACE; |
| 106 tokens[CARRIAGE_RETURN] = WHITESPACE; | 106 tokens[CARRIAGE_RETURN] = WHITESPACE; |
| 107 tokens[SPACE] = WHITESPACE; | 107 tokens[SPACE] = WHITESPACE; |
| 108 tokens[CHAR_0] = NUMBER_LITERAL; | 108 tokens[CHAR_0] = NUMBER_LITERAL; |
| 109 tokens[CHAR_1] = NUMBER_LITERAL; | 109 tokens[CHAR_1] = NUMBER_LITERAL; |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 }); | 508 }); |
| 509 _sb.add('}'); | 509 _sb.add('}'); |
| 510 _seen.removeLast(); | 510 _seen.removeLast(); |
| 511 return; | 511 return; |
| 512 | 512 |
| 513 default: | 513 default: |
| 514 throw const JsonUnsupportedObjectType(); | 514 throw const JsonUnsupportedObjectType(); |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 } | 517 } |
| OLD | NEW |