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

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

Issue 10206022: Require a digit when parsing JSON number. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test cases. Created 8 years, 8 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 | « no previous file | tests/utils/src/JsonTest.dart » ('j') | 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) 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 num _parseNumber() { 275 num _parseNumber() {
276 if (!_isToken(NUMBER_LITERAL)) _error("Expected number literal"); 276 if (!_isToken(NUMBER_LITERAL)) _error("Expected number literal");
277 277
278 final int startPos = position; 278 final int startPos = position;
279 if (_isChar(MINUS)) position++; 279 if (_isChar(MINUS)) position++;
280 if (_isChar(CHAR_0)) { 280 if (_isChar(CHAR_0)) {
281 position++; 281 position++;
282 } else if (_isDigit()) { 282 } else if (_isDigit()) {
283 position++; 283 position++;
284 while (_isDigit()) position++; 284 while (_isDigit()) position++;
285 } else {
286 _error("Expected digit when parsing number");
285 } 287 }
286 288
287 bool isInt = true; 289 bool isInt = true;
288 if (_isChar(DOT)) { 290 if (_isChar(DOT)) {
289 position++; 291 position++;
290 if (_isDigit()) { 292 if (_isDigit()) {
291 isInt = false; 293 isInt = false;
292 while (_isDigit()) position++; 294 while (_isDigit()) position++;
293 } else { 295 } else {
294 position--; // No digit, backtrack. 296 position--; // No digit, backtrack.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 }); 507 });
506 _sb.add('}'); 508 _sb.add('}');
507 _seen.removeLast(); 509 _seen.removeLast();
508 return; 510 return;
509 511
510 default: 512 default:
511 throw const JsonUnsupportedObjectType(); 513 throw const JsonUnsupportedObjectType();
512 } 514 }
513 } 515 }
514 } 516 }
OLDNEW
« no previous file with comments | « no previous file | tests/utils/src/JsonTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698