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

Unified Diff: frog/leg/lib/js_helper.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/leg/lib/js_helper.dart
diff --git a/frog/leg/lib/js_helper.dart b/frog/leg/lib/js_helper.dart
index 1817c5ad354d622daacaa43be50a6bf39e0bec11..4d27fba2efe9ba9952895d6568416f2e92322e27 100644
--- a/frog/leg/lib/js_helper.dart
+++ b/frog/leg/lib/js_helper.dart
@@ -1129,10 +1129,15 @@ class MathNatives {
checkNull(str);
if (str is !String) throw new IllegalArgumentException(str);
var trimmed = str.trim();
- if (!JS('bool', @'/^(0[xX])?[+-]?[0-9]+$/.test($0)', trimmed)) {
+ if (!JS('bool', @'/^[+-]?(0[xX])?[0-9]+$/.test($0)', trimmed)) {
throw new BadNumberFormatException(str);
}
- var ret = JS('num', @'parseInt($0, 10)', str);
+ var base = 10;;
+ if ((trimmed.length > 2 && (trimmed[1] == 'x' || trimmed[1] == 'X')) ||
+ (trimmed.length > 3 && (trimmed[2] == 'x' || trimmed[2] == 'X'))) {
+ base = 16;
+ }
+ var ret = JS('num', @'parseInt($0, $1)', trimmed, base);
if (ret.isNaN()) throw new BadNumberFormatException(str);
return ret;
}

Powered by Google App Engine
This is Rietveld 408576698