diff options
author | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 17:15:41 +0000 |
---|---|---|
committer | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 17:15:41 +0000 |
commit | d9023abb77c05d411835658b1091bdbb592b45c2 (patch) | |
tree | 0fb92b1786b59c2c1a42a0d29d58df697e1b7ec0 /base/string_util.h | |
parent | 9f16de03664224cc286851ca03369cf699dd7c3c (diff) | |
download | chromium_src-d9023abb77c05d411835658b1091bdbb592b45c2.zip chromium_src-d9023abb77c05d411835658b1091bdbb592b45c2.tar.gz chromium_src-d9023abb77c05d411835658b1091bdbb592b45c2.tar.bz2 |
Cross-platform portability fixes for JSONReader. Adds generic string-to-double parsing and tests in string_util.
There is one behavior change here: numbers which "look" like integers by virtue of being free of '.', 'e', and 'E' are no longer rejected if they're not within the [INT_MIN .. INT_MAX] range. Instead, they'll be parsed and stored internally as doubles.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util.h')
-rw-r--r-- | base/string_util.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/base/string_util.h b/base/string_util.h index 129f124..b89694f 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -342,6 +342,14 @@ bool StringToInt64(const std::wstring& input, int64* output); bool HexStringToInt(const std::string& input, int* output); bool HexStringToInt(const std::wstring& input, int* output); +// For floating-point conversions, only conversions of input strings in decimal +// form are defined to work. Behavior with strings representing floating-point +// numbers in hexadecimal, and strings representing non-fininte values (such +// as NaN and inf) is undefined. Otherwise, these behave the same as the +// integral variants above. +bool StringToDouble(const std::string& input, double* output); +bool StringToDouble(const std::wstring& input, double* output); + // Convenience forms of the above, when the caller is uninterested in the // boolean return value. These return only the |*output| value from the // above conversions: a best-effort conversion when possible, otherwise, 0. @@ -351,6 +359,8 @@ int64 StringToInt64(const std::string& value); int64 StringToInt64(const std::wstring& value); int HexStringToInt(const std::string& value); int HexStringToInt(const std::wstring& value); +double StringToDouble(const std::string& value); +double StringToDouble(const std::wstring& value); // Return a C++ string given printf-like input. std::string StringPrintf(const char* format, ...); |