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

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

Issue 10913271: Move parseInt parseDouble to int/double classes as a static method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make int.parse directly native. 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/coreimpl/date.dart ('k') | lib/math/base.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) 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 // JSON parsing and serialization. 9 // JSON parsing and serialization.
10 10
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 break; 324 break;
325 case CHAR_T: 325 case CHAR_T:
326 c = TAB; 326 c = TAB;
327 break; 327 break;
328 case CHAR_U: 328 case CHAR_U:
329 if (position + 5 > length) { 329 if (position + 5 > length) {
330 error('Invalid unicode esacape sequence'); 330 error('Invalid unicode esacape sequence');
331 } 331 }
332 final codeString = json.substring(position + 1, position + 5); 332 final codeString = json.substring(position + 1, position + 5);
333 try { 333 try {
334 c = parseInt('0x${codeString}'); 334 c = int.parse('0x${codeString}');
335 } catch (e) { 335 } catch (e) {
336 error('Invalid unicode esacape sequence'); 336 error('Invalid unicode esacape sequence');
337 } 337 }
338 position += 4; 338 position += 4;
339 break; 339 break;
340 default: 340 default:
341 error('Invalid esacape sequence in string literal'); 341 error('Invalid esacape sequence in string literal');
342 } 342 }
343 } 343 }
344 charCodes.add(c); 344 charCodes.add(c);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 char = nextChar(); 382 char = nextChar();
383 isInt = false; 383 isInt = false;
384 while (isDigit(char)) char = nextChar(); 384 while (isDigit(char)) char = nextChar();
385 } else { 385 } else {
386 error('Expected digit following \'e\' or \'E\''); 386 error('Expected digit following \'e\' or \'E\'');
387 } 387 }
388 } 388 }
389 389
390 String number = json.substring(startPos, position); 390 String number = json.substring(startPos, position);
391 if (isInt) { 391 if (isInt) {
392 return parseInt(number); 392 return int.parse(number);
393 } else { 393 } else {
394 return parseDouble(number); 394 return double.parse(number);
395 } 395 }
396 } 396 }
397 397
398 bool isChar(int char) { 398 bool isChar(int char) {
399 if (position >= length) return false; 399 if (position >= length) return false;
400 return json.charCodeAt(position) == char; 400 return json.charCodeAt(position) == char;
401 } 401 }
402 402
403 bool isDigit(int char) { 403 bool isDigit(int char) {
404 return char >= CHAR_0 && char <= CHAR_9; 404 return char >= CHAR_0 && char <= CHAR_9;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 first = false; 593 first = false;
594 }); 594 });
595 sb.add('}'); 595 sb.add('}');
596 seen.removeLast(); 596 seen.removeLast();
597 return true; 597 return true;
598 } else { 598 } else {
599 return false; 599 return false;
600 } 600 }
601 } 601 }
602 } 602 }
OLDNEW
« no previous file with comments | « lib/coreimpl/date.dart ('k') | lib/math/base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698