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

Unified Diff: src/conversions.cc

Issue 2847: Simplify logic in string-to-double conversion code.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/conversions.cc
===================================================================
--- src/conversions.cc (revision 293)
+++ src/conversions.cc (working copy)
@@ -269,18 +269,27 @@
// Skip leading spaces.
while ((index < len) && IsSpace(str, index)) index++;
- // Compute sign of result.
+ // Is the string empty?
+ if (index >= len) return empty_string_val;
+
+ // Get the first character.
+ uint16_t fst = GetChar(str, index);
+
+ // Numbers can only start with '-', '+', '.', 'I' (Infinity), or a digit.
+ if (fst != '-' && fst != '+' && fst != '.' && fst != 'I' &&
+ (fst > '9' || fst < '0')) {
+ return JUNK_STRING_VALUE;
+ }
+
+ // Compute sign of result based on first character.
int sign = 1;
- if (index < len && GetChar(str, index) == '-') {
+ if (fst == '-') {
sign = -1;
index++;
// String only containing a '-' are junk chars.
if (index == len) return JUNK_STRING_VALUE;
}
- // string is empty?
- if (index >= len) return empty_string_val;
-
// do we have a hex number?
// (since the string is 0-terminated, it's ok to look one char beyond the end)
if ((flags & ALLOW_HEX) != 0 &&
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698