Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Side by Side Diff: lib/json/json.dart

Issue 10891022: Update corelib/ and lib/ to use the new try-catch syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/html/src/XMLElementWrappingImplementation.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
121 return 0; 121 return 0;
122 } 122 }
123 try { 123 try {
124 p._parseObject(); 124 p._parseObject();
125 assert(p.position <= p.length); 125 assert(p.position <= p.length);
126 return p.position; 126 return p.position;
127 } catch (var e) { 127 } catch (e) {
128 return 0; 128 return 0;
129 } 129 }
130 } 130 }
131 131
132 _JsonParser._internal(String json) 132 _JsonParser._internal(String json)
133 : json = json, 133 : json = json,
134 length = json.length { 134 length = json.length {
135 if (tokens !== null) return; 135 if (tokens !== null) return;
136 136
137 // Use a list as jump-table, faster then switch and if. 137 // Use a list as jump-table, faster then switch and if.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 case CHAR_T: 285 case CHAR_T:
286 c = TAB; 286 c = TAB;
287 break; 287 break;
288 case CHAR_U: 288 case CHAR_U:
289 if (position + 5 > length) { 289 if (position + 5 > length) {
290 _error('Invalid unicode esacape sequence'); 290 _error('Invalid unicode esacape sequence');
291 } 291 }
292 final codeString = json.substring(position + 1, position + 5); 292 final codeString = json.substring(position + 1, position + 5);
293 try { 293 try {
294 c = parseInt('0x${codeString}'); 294 c = parseInt('0x${codeString}');
295 } catch (var e) { 295 } catch (e) {
296 _error('Invalid unicode esacape sequence'); 296 _error('Invalid unicode esacape sequence');
297 } 297 }
298 position += 4; 298 position += 4;
299 break; 299 break;
300 default: 300 default:
301 _error('Invalid esacape sequence in string literal'); 301 _error('Invalid esacape sequence in string literal');
302 } 302 }
303 } 303 }
304 charCodes.add(c); 304 charCodes.add(c);
305 position++; 305 position++;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « lib/html/src/XMLElementWrappingImplementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698