| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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("dart:json"); | 5 #library("dart:json"); |
| 6 | 6 |
| 7 #import('dart:math'); | 7 #import('dart:math'); |
| 8 | 8 |
| 9 // Pure Dart implementation of JSON protocol. | 9 // Pure Dart implementation of JSON protocol. |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 position = position, | 51 position = position, |
| 52 message = 'JSONParseException: $message, at offset $position'; | 52 message = 'JSONParseException: $message, at offset $position'; |
| 53 | 53 |
| 54 String toString() => message; | 54 String toString() => message; |
| 55 | 55 |
| 56 final String message; | 56 final String message; |
| 57 final int position; | 57 final int position; |
| 58 } | 58 } |
| 59 | 59 |
| 60 class _JsonParser { | 60 class _JsonParser { |
| 61 static final int BACKSPACE = 8; | 61 static const int BACKSPACE = 8; |
| 62 static final int TAB = 9; | 62 static const int TAB = 9; |
| 63 static final int NEW_LINE = 10; | 63 static const int NEW_LINE = 10; |
| 64 static final int FORM_FEED = 12; | 64 static const int FORM_FEED = 12; |
| 65 static final int CARRIAGE_RETURN = 13; | 65 static const int CARRIAGE_RETURN = 13; |
| 66 static final int SPACE = 32; | 66 static const int SPACE = 32; |
| 67 static final int QUOTE = 34; | 67 static const int QUOTE = 34; |
| 68 static final int PLUS = 43; | 68 static const int PLUS = 43; |
| 69 static final int COMMA = 44; | 69 static const int COMMA = 44; |
| 70 static final int MINUS = 45; | 70 static const int MINUS = 45; |
| 71 static final int DOT = 46; | 71 static const int DOT = 46; |
| 72 static final int SLASH = 47; | 72 static const int SLASH = 47; |
| 73 static final int CHAR_0 = 48; | 73 static const int CHAR_0 = 48; |
| 74 static final int CHAR_1 = 49; | 74 static const int CHAR_1 = 49; |
| 75 static final int CHAR_2 = 50; | 75 static const int CHAR_2 = 50; |
| 76 static final int CHAR_3 = 51; | 76 static const int CHAR_3 = 51; |
| 77 static final int CHAR_4 = 52; | 77 static const int CHAR_4 = 52; |
| 78 static final int CHAR_5 = 53; | 78 static const int CHAR_5 = 53; |
| 79 static final int CHAR_6 = 54; | 79 static const int CHAR_6 = 54; |
| 80 static final int CHAR_7 = 55; | 80 static const int CHAR_7 = 55; |
| 81 static final int CHAR_8 = 56; | 81 static const int CHAR_8 = 56; |
| 82 static final int CHAR_9 = 57; | 82 static const int CHAR_9 = 57; |
| 83 static final int COLON = 58; | 83 static const int COLON = 58; |
| 84 static final int CHAR_CAPITAL_E = 69; | 84 static const int CHAR_CAPITAL_E = 69; |
| 85 static final int LBRACKET = 91; | 85 static const int LBRACKET = 91; |
| 86 static final int BACKSLASH = 92; | 86 static const int BACKSLASH = 92; |
| 87 static final int RBRACKET = 93; | 87 static const int RBRACKET = 93; |
| 88 static final int CHAR_B = 98; | 88 static const int CHAR_B = 98; |
| 89 static final int CHAR_E = 101; | 89 static const int CHAR_E = 101; |
| 90 static final int CHAR_F = 102; | 90 static const int CHAR_F = 102; |
| 91 static final int CHAR_N = 110; | 91 static const int CHAR_N = 110; |
| 92 static final int CHAR_R = 114; | 92 static const int CHAR_R = 114; |
| 93 static final int CHAR_T = 116; | 93 static const int CHAR_T = 116; |
| 94 static final int CHAR_U = 117; | 94 static const int CHAR_U = 117; |
| 95 static final int LBRACE = 123; | 95 static const int LBRACE = 123; |
| 96 static final int RBRACE = 125; | 96 static const int RBRACE = 125; |
| 97 | 97 |
| 98 static final int STRING_LITERAL = QUOTE; | 98 static const int STRING_LITERAL = QUOTE; |
| 99 static final int NUMBER_LITERAL = MINUS; | 99 static const int NUMBER_LITERAL = MINUS; |
| 100 static final int NULL_LITERAL = CHAR_N; | 100 static const int NULL_LITERAL = CHAR_N; |
| 101 static final int FALSE_LITERAL = CHAR_F; | 101 static const int FALSE_LITERAL = CHAR_F; |
| 102 static final int TRUE_LITERAL = CHAR_T; | 102 static const int TRUE_LITERAL = CHAR_T; |
| 103 | 103 |
| 104 static final int WHITESPACE = SPACE; | 104 static const int WHITESPACE = SPACE; |
| 105 | 105 |
| 106 static final int LAST_ASCII = RBRACE; | 106 static const int LAST_ASCII = RBRACE; |
| 107 | 107 |
| 108 static final String NULL_STRING = "null"; | 108 static const String NULL_STRING = "null"; |
| 109 static final String TRUE_STRING = "true"; | 109 static const String TRUE_STRING = "true"; |
| 110 static final String FALSE_STRING = "false"; | 110 static const String FALSE_STRING = "false"; |
| 111 | 111 |
| 112 | 112 |
| 113 static parse(String json) { | 113 static parse(String json) { |
| 114 return new _JsonParser._internal(json)._parseToplevel(); | 114 return new _JsonParser._internal(json)._parseToplevel(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 static objectLength(String str) { | 117 static objectLength(String str) { |
| 118 var p = new _JsonParser._internal(str); | 118 var p = new _JsonParser._internal(str); |
| 119 var firstToken = p._token(); | 119 var firstToken = p._token(); |
| 120 if (firstToken != LBRACE) { | 120 if (firstToken != LBRACE) { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 first = false; | 548 first = false; |
| 549 }); | 549 }); |
| 550 _sb.add('}'); | 550 _sb.add('}'); |
| 551 _seen.removeLast(); | 551 _seen.removeLast(); |
| 552 return; | 552 return; |
| 553 } else { | 553 } else { |
| 554 throw const JsonUnsupportedObjectType(); | 554 throw const JsonUnsupportedObjectType(); |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 } | 557 } |
| OLD | NEW |