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

Side by Side Diff: runtime/lib/double_patch.dart

Issue 15333006: Rewrite double.parse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Upload Created 7 years, 7 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 | « runtime/lib/double.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('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 // Dart core library. 4 // Dart core library.
5 5
6 // VM implementation of double. 6 // VM implementation of double.
7 7
8 patch class double { 8 patch class double {
9 static double _parse(String string) native "Double_parse"; 9
10 static double _native_parse(_OneByteString string) native "Double_parse";
11
12 static double _parse(var str) {
13 str = str.trim();
14
15 if (str.length == 0) return null;
16
17 final ccid = str._cid;
18 _OneByteString oneByteString;
19 // TODO(floitsch): Allow _ExternalOneByteStrings. As of May 2013 they don't
20 // have any _classId.
21 if (ccid != _OneByteString._classId) {
22 int length = str.length;
23 var s = _OneByteString._allocate(length);
24 for (int i = 0; i < length; i++) {
25 int currentUnit = str.codeUnitAt(i);
26 // All valid trimmed double strings must be ASCII.
27 if (currentUnit < 128) {
28 s._setAt(i, currentUnit);
29 } else {
30 return null;
31 }
32 }
33 oneByteString = s;
34 } else {
35 oneByteString = str;
36 }
37
38 return _native_parse(oneByteString);
39 }
10 40
11 /* patch */ static double parse(String str, 41 /* patch */ static double parse(String str,
12 [double handleError(String str)]) { 42 [double handleError(String str)]) {
13 if (handleError == null) return _parse(str); 43 var result = _parse(str);
14 try { 44 if (result == null) {
15 return _parse(str); 45 if (handleError == null) throw new FormatException(str);
16 } on FormatException {
17 return handleError(str); 46 return handleError(str);
18 } 47 }
48 return result;
19 } 49 }
20 } 50 }
OLDNEW
« no previous file with comments | « runtime/lib/double.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698