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

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: Rebase. 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
« no previous file with comments | « frog/leg/lib/date_helper.dart ('k') | frog/leg/lib/mockimpl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..67fe76b9e3fd5beadcd59b9e96337335984ec986 100644
--- a/frog/leg/lib/js_helper.dart
+++ b/frog/leg/lib/js_helper.dart
@@ -1128,11 +1128,16 @@ class MathNatives {
static int parseInt(str) {
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', @'/^\s*[+-]?(0[xX])?\d+\s*$/.test($0)', str)) {
throw new BadNumberFormatException(str);
}
- var ret = JS('num', @'parseInt($0, 10)', str);
+ var trimmed = str.trim();
+ 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;
}
« no previous file with comments | « frog/leg/lib/date_helper.dart ('k') | frog/leg/lib/mockimpl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698