2012-09-17 07:25:38 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Dart core library.
|
|
|
|
|
|
|
|
// VM implementation of double.
|
|
|
|
|
|
|
|
patch class double {
|
2013-05-23 14:30:16 +00:00
|
|
|
|
2014-07-01 11:59:31 +00:00
|
|
|
static double _nativeParse(String str,
|
|
|
|
int start, int end) native "Double_parse";
|
2013-05-23 14:30:16 +00:00
|
|
|
|
|
|
|
static double _parse(var str) {
|
2014-07-01 11:59:31 +00:00
|
|
|
int len = str.length;
|
|
|
|
int start = str._firstNonWhitespace();
|
|
|
|
if (start == len) return null; // All whitespace.
|
|
|
|
int end = str._lastNonWhitespace() + 1;
|
|
|
|
assert(start < end);
|
2013-05-23 14:30:16 +00:00
|
|
|
|
2014-07-01 11:59:31 +00:00
|
|
|
return _nativeParse(str, start, end);
|
2013-05-23 14:30:16 +00:00
|
|
|
}
|
2013-01-07 11:23:16 +00:00
|
|
|
|
|
|
|
/* patch */ static double parse(String str,
|
2013-08-16 12:41:07 +00:00
|
|
|
[double onError(String str)]) {
|
2013-05-23 14:30:16 +00:00
|
|
|
var result = _parse(str);
|
|
|
|
if (result == null) {
|
2014-07-14 07:47:45 +00:00
|
|
|
if (onError == null) throw new FormatException("Invalid double", str);
|
2013-08-16 12:41:07 +00:00
|
|
|
return onError(str);
|
2013-01-07 11:23:16 +00:00
|
|
|
}
|
2013-05-23 14:30:16 +00:00
|
|
|
return result;
|
2013-01-07 11:23:16 +00:00
|
|
|
}
|
2012-09-17 07:25:38 +00:00
|
|
|
}
|