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

Unified Diff: frog/lib/math.dart

Issue 9568011: Unify Date.fromString and support more Iso 8601. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve parseInt. Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: frog/lib/math.dart
diff --git a/frog/lib/math.dart b/frog/lib/math.dart
index 46c3beaae1fc4d8e2bfd03e0cdeec6c141a51012..9e53624642af4707dbf01ae796d2bf850b25df0e 100644
--- a/frog/lib/math.dart
+++ b/frog/lib/math.dart
@@ -50,7 +50,10 @@ class Math native 'Math' {
* an [int]. Throws a [BadNumberFormatException] if [str]
* cannot be parsed as an [int].
*/
- static int parseInt(String str) native '''var ret = parseInt(str);
+ static int parseInt(String str) native '''
+ var isHex = (str.length > 2) && str[0] == '0' &&
kasperl 2012/03/02 13:34:10 Do you need to trim first?
floitsch 2012/03/02 17:00:29 Using a regexp now.
+ (str[1] == 'x' || str[1] == 'X');
+ var ret = parseInt(str, isHex ? 16 : 10);
if (isNaN(ret)) \$throw(new BadNumberFormatException(str));
return ret;''' { throw new BadNumberFormatException(""); }

Powered by Google App Engine
This is Rietveld 408576698