diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 14:39:42 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 14:39:42 +0000 |
commit | c9c07779224d9dd320323943a569dbf2e416a411 (patch) | |
tree | a040e1ca03410c7cb37547b16b5a0fb8bea67dde | |
parent | be1ce6a7b2fa7e9622e5b249abd5fab478b6ca05 (diff) | |
download | chromium_src-c9c07779224d9dd320323943a569dbf2e416a411.zip chromium_src-c9c07779224d9dd320323943a569dbf2e416a411.tar.gz chromium_src-c9c07779224d9dd320323943a569dbf2e416a411.tar.bz2 |
Remove number conversion functions from string_util. These moved to string_number_conversions.
TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/3054036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54747 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 85 insertions, 627 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index 98f48c7..8d2413b 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -59,239 +59,8 @@ static bool CompareParameter(const ReplacementOffset& elem1, return elem1.parameter < elem2.parameter; } -// Generalized string-to-number conversion. -// -// StringToNumberTraits should provide: -// - a typedef for string_type, the STL string type used as input. -// - a typedef for value_type, the target numeric type. -// - a static function, convert_func, which dispatches to an appropriate -// strtol-like function and returns type value_type. -// - a static function, valid_func, which validates |input| and returns a bool -// indicating whether it is in proper form. This is used to check for -// conditions that convert_func tolerates but should result in -// StringToNumber returning false. For strtol-like funtions, valid_func -// should check for leading whitespace. -template<typename StringToNumberTraits> -bool StringToNumber(const typename StringToNumberTraits::string_type& input, - typename StringToNumberTraits::value_type* output) { - typedef StringToNumberTraits traits; - - errno = 0; // Thread-safe? It is on at least Mac, Linux, and Windows. - typename traits::string_type::value_type* endptr = NULL; - typename traits::value_type value = traits::convert_func(input.c_str(), - &endptr); - *output = value; - - // Cases to return false: - // - If errno is ERANGE, there was an overflow or underflow. - // - If the input string is empty, there was nothing to parse. - // - If endptr does not point to the end of the string, there are either - // characters remaining in the string after a parsed number, or the string - // does not begin with a parseable number. endptr is compared to the - // expected end given the string's stated length to correctly catch cases - // where the string contains embedded NUL characters. - // - valid_func determines that the input is not in preferred form. - return errno == 0 && - !input.empty() && - input.c_str() + input.length() == endptr && - traits::valid_func(input); -} - -static int strtoi(const char *nptr, char **endptr, int base) { - long res = strtol(nptr, endptr, base); -#if __LP64__ - // Long is 64-bits, we have to handle under/overflow ourselves. - if (res > kint32max) { - res = kint32max; - errno = ERANGE; - } else if (res < kint32min) { - res = kint32min; - errno = ERANGE; - } -#endif - return static_cast<int>(res); -} - -static unsigned int strtoui(const char *nptr, char **endptr, int base) { - unsigned long res = strtoul(nptr, endptr, base); -#if __LP64__ - // Long is 64-bits, we have to handle under/overflow ourselves. Test to see - // if the result can fit into 32-bits (as signed or unsigned). - if (static_cast<int>(static_cast<long>(res)) != static_cast<long>(res) && - static_cast<unsigned int>(res) != res) { - res = kuint32max; - errno = ERANGE; - } -#endif - return static_cast<unsigned int>(res); -} - -class StringToIntTraits { - public: - typedef std::string string_type; - typedef int value_type; - static const int kBase = 10; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { - return strtoi(str, endptr, kBase); - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !isspace(str[0]); - } -}; - -class String16ToIntTraits { - public: - typedef string16 string_type; - typedef int value_type; - static const int kBase = 10; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { -#if defined(WCHAR_T_IS_UTF16) - return wcstol(str, endptr, kBase); -#elif defined(WCHAR_T_IS_UTF32) - std::string ascii_string = UTF16ToASCII(string16(str)); - char* ascii_end = NULL; - value_type ret = strtoi(ascii_string.c_str(), &ascii_end, kBase); - if (ascii_string.c_str() + ascii_string.length() == ascii_end) { - *endptr = - const_cast<string_type::value_type*>(str) + ascii_string.length(); - } - return ret; -#endif - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !iswspace(str[0]); - } -}; - -class StringToInt64Traits { - public: - typedef std::string string_type; - typedef int64 value_type; - static const int kBase = 10; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { -#ifdef OS_WIN - return _strtoi64(str, endptr, kBase); -#else // assume OS_POSIX - return strtoll(str, endptr, kBase); -#endif - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !isspace(str[0]); - } -}; - -class String16ToInt64Traits { - public: - typedef string16 string_type; - typedef int64 value_type; - static const int kBase = 10; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { -#ifdef OS_WIN - return _wcstoi64(str, endptr, kBase); -#else // assume OS_POSIX - std::string ascii_string = UTF16ToASCII(string16(str)); - char* ascii_end = NULL; - value_type ret = strtoll(ascii_string.c_str(), &ascii_end, kBase); - if (ascii_string.c_str() + ascii_string.length() == ascii_end) { - *endptr = - const_cast<string_type::value_type*>(str) + ascii_string.length(); - } - return ret; -#endif - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !iswspace(str[0]); - } -}; - -// For the HexString variants, use the unsigned variants like strtoul for -// convert_func so that input like "0x80000000" doesn't result in an overflow. - -class HexStringToIntTraits { - public: - typedef std::string string_type; - typedef int value_type; - static const int kBase = 16; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { - return strtoui(str, endptr, kBase); - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !isspace(str[0]); - } -}; - -class HexString16ToIntTraits { - public: - typedef string16 string_type; - typedef int value_type; - static const int kBase = 16; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { -#if defined(WCHAR_T_IS_UTF16) - return wcstoul(str, endptr, kBase); -#elif defined(WCHAR_T_IS_UTF32) - std::string ascii_string = UTF16ToASCII(string16(str)); - char* ascii_end = NULL; - value_type ret = strtoui(ascii_string.c_str(), &ascii_end, kBase); - if (ascii_string.c_str() + ascii_string.length() == ascii_end) { - *endptr = - const_cast<string_type::value_type*>(str) + ascii_string.length(); - } - return ret; -#endif - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !iswspace(str[0]); - } -}; - -class StringToDoubleTraits { - public: - typedef std::string string_type; - typedef double value_type; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { - return dmg_fp::strtod(str, endptr); - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !isspace(str[0]); - } -}; - -class String16ToDoubleTraits { - public: - typedef string16 string_type; - typedef double value_type; - static inline value_type convert_func(const string_type::value_type* str, - string_type::value_type** endptr) { - // Because dmg_fp::strtod does not like char16, we convert it to ASCII. - // In theory, this should be safe, but it's possible that 16-bit chars - // might get ignored by accident causing something to be parsed when it - // shouldn't. - std::string ascii_string = UTF16ToASCII(string16(str)); - char* ascii_end = NULL; - value_type ret = dmg_fp::strtod(ascii_string.c_str(), &ascii_end); - if (ascii_string.c_str() + ascii_string.length() == ascii_end) { - // Put endptr at end of input string, so it's not recognized as an error. - *endptr = - const_cast<string_type::value_type*>(str) + ascii_string.length(); - } - - return ret; - } - static inline bool valid_func(const string_type& str) { - return !str.empty() && !iswspace(str[0]); - } -}; - } // namespace - namespace base { bool IsWprintfFormatPortable(const wchar_t* format) { @@ -329,7 +98,6 @@ bool IsWprintfFormatPortable(const wchar_t* format) { return true; } - } // namespace base @@ -1081,141 +849,6 @@ static void StringAppendVT(StringType* dst, } } -namespace { - -template <typename STR, typename INT, typename UINT, bool NEG> -struct IntToStringT { - // This is to avoid a compiler warning about unary minus on unsigned type. - // For example, say you had the following code: - // template <typename INT> - // INT abs(INT value) { return value < 0 ? -value : value; } - // Even though if INT is unsigned, it's impossible for value < 0, so the - // unary minus will never be taken, the compiler will still generate a - // warning. We do a little specialization dance... - template <typename INT2, typename UINT2, bool NEG2> - struct ToUnsignedT { }; - - template <typename INT2, typename UINT2> - struct ToUnsignedT<INT2, UINT2, false> { - static UINT2 ToUnsigned(INT2 value) { - return static_cast<UINT2>(value); - } - }; - - template <typename INT2, typename UINT2> - struct ToUnsignedT<INT2, UINT2, true> { - static UINT2 ToUnsigned(INT2 value) { - return static_cast<UINT2>(value < 0 ? -value : value); - } - }; - - // This set of templates is very similar to the above templates, but - // for testing whether an integer is negative. - template <typename INT2, bool NEG2> - struct TestNegT { }; - template <typename INT2> - struct TestNegT<INT2, false> { - static bool TestNeg(INT2 value) { - // value is unsigned, and can never be negative. - return false; - } - }; - template <typename INT2> - struct TestNegT<INT2, true> { - static bool TestNeg(INT2 value) { - return value < 0; - } - }; - - static STR IntToString(INT value) { - // log10(2) ~= 0.3 bytes needed per bit or per byte log10(2**8) ~= 2.4. - // So round up to allocate 3 output characters per byte, plus 1 for '-'. - const int kOutputBufSize = 3 * sizeof(INT) + 1; - - // Allocate the whole string right away, we will right back to front, and - // then return the substr of what we ended up using. - STR outbuf(kOutputBufSize, 0); - - bool is_neg = TestNegT<INT, NEG>::TestNeg(value); - // Even though is_neg will never be true when INT is parameterized as - // unsigned, even the presence of the unary operation causes a warning. - UINT res = ToUnsignedT<INT, UINT, NEG>::ToUnsigned(value); - - for (typename STR::iterator it = outbuf.end();;) { - --it; - DCHECK(it != outbuf.begin()); - *it = static_cast<typename STR::value_type>((res % 10) + '0'); - res /= 10; - - // We're done.. - if (res == 0) { - if (is_neg) { - --it; - DCHECK(it != outbuf.begin()); - *it = static_cast<typename STR::value_type>('-'); - } - return STR(it, outbuf.end()); - } - } - NOTREACHED(); - return STR(); - } -}; - -} - -std::string IntToString(int value) { - return IntToStringT<std::string, int, unsigned int, true>:: - IntToString(value); -} -std::wstring IntToWString(int value) { - return IntToStringT<std::wstring, int, unsigned int, true>:: - IntToString(value); -} -string16 IntToString16(int value) { - return IntToStringT<string16, int, unsigned int, true>:: - IntToString(value); -} -std::string UintToString(unsigned int value) { - return IntToStringT<std::string, unsigned int, unsigned int, false>:: - IntToString(value); -} -std::wstring UintToWString(unsigned int value) { - return IntToStringT<std::wstring, unsigned int, unsigned int, false>:: - IntToString(value); -} -string16 UintToString16(unsigned int value) { - return IntToStringT<string16, unsigned int, unsigned int, false>:: - IntToString(value); -} -std::string Int64ToString(int64 value) { - return IntToStringT<std::string, int64, uint64, true>:: - IntToString(value); -} -std::wstring Int64ToWString(int64 value) { - return IntToStringT<std::wstring, int64, uint64, true>:: - IntToString(value); -} -std::string Uint64ToString(uint64 value) { - return IntToStringT<std::string, uint64, uint64, false>:: - IntToString(value); -} -std::wstring Uint64ToWString(uint64 value) { - return IntToStringT<std::wstring, uint64, uint64, false>:: - IntToString(value); -} - -std::string DoubleToString(double value) { - // According to g_fmt.cc, it is sufficient to declare a buffer of size 32. - char buffer[32]; - dmg_fp::g_fmt(buffer, value); - return std::string(buffer); -} - -std::wstring DoubleToWString(double value) { - return ASCIIToWide(DoubleToString(value)); -} - void StringAppendV(std::string* dst, const char* format, va_list ap) { StringAppendVT(dst, format, ap); } @@ -1705,128 +1338,6 @@ bool MatchPatternASCII(const std::string& eval, const std::string& pattern) { return MatchPatternT(eval.c_str(), pattern.c_str(), 0); } -bool StringToInt(const std::string& input, int* output) { - return StringToNumber<StringToIntTraits>(input, output); -} - -bool StringToInt(const string16& input, int* output) { - return StringToNumber<String16ToIntTraits>(input, output); -} - -bool StringToInt64(const std::string& input, int64* output) { - return StringToNumber<StringToInt64Traits>(input, output); -} - -bool StringToInt64(const string16& input, int64* output) { - return StringToNumber<String16ToInt64Traits>(input, output); -} - -bool HexStringToInt(const std::string& input, int* output) { - return StringToNumber<HexStringToIntTraits>(input, output); -} - -bool HexStringToInt(const string16& input, int* output) { - return StringToNumber<HexString16ToIntTraits>(input, output); -} - -namespace { - -template<class CHAR> -bool HexDigitToIntT(const CHAR digit, uint8* val) { - if (digit >= '0' && digit <= '9') - *val = digit - '0'; - else if (digit >= 'a' && digit <= 'f') - *val = 10 + digit - 'a'; - else if (digit >= 'A' && digit <= 'F') - *val = 10 + digit - 'A'; - else - return false; - return true; -} - -template<typename STR> -bool HexStringToBytesT(const STR& input, std::vector<uint8>* output) { - DCHECK(output->size() == 0); - size_t count = input.size(); - if (count == 0 || (count % 2) != 0) - return false; - for (uintptr_t i = 0; i < count / 2; ++i) { - uint8 msb = 0; // most significant 4 bits - uint8 lsb = 0; // least significant 4 bits - if (!HexDigitToIntT(input[i * 2], &msb) || - !HexDigitToIntT(input[i * 2 + 1], &lsb)) - return false; - output->push_back((msb << 4) | lsb); - } - return true; -} - -} // namespace - -bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { - return HexStringToBytesT(input, output); -} - -bool HexStringToBytes(const string16& input, std::vector<uint8>* output) { - return HexStringToBytesT(input, output); -} - -int StringToInt(const std::string& value) { - int result; - StringToInt(value, &result); - return result; -} - -int StringToInt(const string16& value) { - int result; - StringToInt(value, &result); - return result; -} - -int64 StringToInt64(const std::string& value) { - int64 result; - StringToInt64(value, &result); - return result; -} - -int64 StringToInt64(const string16& value) { - int64 result; - StringToInt64(value, &result); - return result; -} - -int HexStringToInt(const std::string& value) { - int result; - HexStringToInt(value, &result); - return result; -} - -int HexStringToInt(const string16& value) { - int result; - HexStringToInt(value, &result); - return result; -} - -bool StringToDouble(const std::string& input, double* output) { - return StringToNumber<StringToDoubleTraits>(input, output); -} - -bool StringToDouble(const string16& input, double* output) { - return StringToNumber<String16ToDoubleTraits>(input, output); -} - -double StringToDouble(const std::string& value) { - double result; - StringToDouble(value, &result); - return result; -} - -double StringToDouble(const string16& value) { - double result; - StringToDouble(value, &result); - return result; -} - // The following code is compatible with the OpenBSD lcpy interface. See: // http://www.gratisoft.us/todd/papers/strlcpy.html // ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/{wcs,str}lcpy.c @@ -1894,17 +1405,3 @@ bool ElideString(const std::wstring& input, int max_len, std::wstring* output) { return true; } - -std::string HexEncode(const void* bytes, size_t size) { - static const char kHexChars[] = "0123456789ABCDEF"; - - // Each input byte creates two output hex characters. - std::string ret(size * 2, '\0'); - - for (size_t i = 0; i < size; ++i) { - char b = reinterpret_cast<const char*>(bytes)[i]; - ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; - ret[(i * 2) + 1] = kHexChars[b & 0xf]; - } - return ret; -} diff --git a/base/string_util.h b/base/string_util.h index 97b5100..9edf85f 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -449,67 +449,6 @@ void ReplaceSubstringsAfterOffset(std::string* str, const std::string& find_this, const std::string& replace_with); -// Specialized string-conversion functions. -std::string IntToString(int value); -std::wstring IntToWString(int value); -string16 IntToString16(int value); -std::string UintToString(unsigned int value); -std::wstring UintToWString(unsigned int value); -string16 UintToString16(unsigned int value); -std::string Int64ToString(int64 value); -std::wstring Int64ToWString(int64 value); -std::string Uint64ToString(uint64 value); -std::wstring Uint64ToWString(uint64 value); -// The DoubleToString methods convert the double to a string format that -// ignores the locale. If you want to use locale specific formatting, use ICU. -std::string DoubleToString(double value); -std::wstring DoubleToWString(double value); - -// Perform a best-effort conversion of the input string to a numeric type, -// setting |*output| to the result of the conversion. Returns true for -// "perfect" conversions; returns false in the following cases: -// - Overflow/underflow. |*output| will be set to the maximum value supported -// by the data type. -// - Trailing characters in the string after parsing the number. |*output| -// will be set to the value of the number that was parsed. -// - No characters parseable as a number at the beginning of the string. -// |*output| will be set to 0. -// - Empty string. |*output| will be set to 0. -bool StringToInt(const std::string& input, int* output); -bool StringToInt(const string16& input, int* output); -bool StringToInt64(const std::string& input, int64* output); -bool StringToInt64(const string16& input, int64* output); -bool HexStringToInt(const std::string& input, int* output); -bool HexStringToInt(const string16& input, int* output); - -// Similar to the previous functions, except that output is a vector of bytes. -// |*output| will contain as many bytes as were successfully parsed prior to the -// error. There is no overflow, but input.size() must be evenly divisible by 2. -// Leading 0x or +/- are not allowed. -bool HexStringToBytes(const std::string& input, std::vector<uint8>* output); -bool HexStringToBytes(const string16& input, std::vector<uint8>* 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. This expects the input string to NOT be specific to the locale. -// If your input is locale specific, use ICU to read the number. -bool StringToDouble(const std::string& input, double* output); -bool StringToDouble(const string16& 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. -int StringToInt(const std::string& value); -int StringToInt(const string16& value); -int64 StringToInt64(const std::string& value); -int64 StringToInt64(const string16& value); -int HexStringToInt(const std::string& value); -int HexStringToInt(const string16& value); -double StringToDouble(const std::string& value); -double StringToDouble(const string16& value); - // Return a C++ string given printf-like input. std::string StringPrintf(const char* format, ...) PRINTF_FORMAT(1, 2); std::wstring StringPrintf(const wchar_t* format, ...) WPRINTF_FORMAT(1, 2); @@ -685,15 +624,6 @@ bool ElideString(const std::wstring& input, int max_len, std::wstring* output); bool MatchPatternWide(const std::wstring& string, const std::wstring& pattern); bool MatchPatternASCII(const std::string& string, const std::string& pattern); -// Returns a hex string representation of a binary buffer. -// The returned hex string will be in upper case. -// This function does not check if |size| is within reasonable limits since -// it's written with trusted data in mind. -// If you suspect that the data you want to format might be large, -// the absolute max size for |size| should be is -// std::numeric_limits<size_t>::max() / 2 -std::string HexEncode(const void* bytes, size_t size); - // Hack to convert any char-like type to its unsigned counterpart. // For example, it will convert char, signed char and unsigned char to unsigned // char. diff --git a/chrome/browser/cocoa/authorization_util.mm b/chrome/browser/cocoa/authorization_util.mm index a879db2..fdd4387 100644 --- a/chrome/browser/cocoa/authorization_util.mm +++ b/chrome/browser/cocoa/authorization_util.mm @@ -13,6 +13,7 @@ #include "base/eintr_wrapper.h" #include "base/logging.h" #import "base/mac_util.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "chrome/browser/cocoa/scoped_authorizationref.h" @@ -118,7 +119,7 @@ OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization, --line_length; } std::string line(line_c, line_length); - if (!StringToInt(line, &line_pid)) { + if (!base::StringToInt(line, &line_pid)) { // StringToInt may have set line_pid to something, but if the conversion // was imperfect, use -1. LOG(ERROR) << "ExecuteWithPrivilegesAndGetPid: funny line: " << line; diff --git a/chrome/browser/cocoa/find_bar_text_field_cell.mm b/chrome/browser/cocoa/find_bar_text_field_cell.mm index 9b52c5f..9c41ad5 100644 --- a/chrome/browser/cocoa/find_bar_text_field_cell.mm +++ b/chrome/browser/cocoa/find_bar_text_field_cell.mm @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "base/logging.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "grit/generated_resources.h" @@ -65,9 +66,10 @@ CGFloat WidthForResults(NSAttributedString* resultsString) { - (void)setActiveMatch:(NSInteger)current of:(NSInteger)total { NSString* results = - base::SysWideToNSString(l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, - IntToWString(current), - IntToWString(total))); + base::SysUTF16ToNSString(l10n_util::GetStringFUTF16( + IDS_FIND_IN_PAGE_COUNT, + base::IntToString16(current), + base::IntToString16(total))); resultsString_.reset([[NSAttributedString alloc] initWithString:results attributes:[self resultsAttributes:(total > 0)]]); diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc index d885ad7..9e2c87c 100644 --- a/chrome/browser/first_run/first_run_win.cc +++ b/chrome/browser/first_run/first_run_win.cc @@ -24,6 +24,7 @@ #include "base/process_util.h" #include "base/registry.h" #include "base/scoped_comptr_win.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/win_util.h" #include "chrome/common/chrome_constants.h" @@ -591,13 +592,13 @@ bool DecodeImportParams(const std::wstring& encoded, if (v.size() != 3) return false; - if (!StringToInt(v[0], browser_type)) + if (!base::StringToInt(v[0], browser_type)) return false; - if (!StringToInt(v[1], options)) + if (!base::StringToInt(v[1], options)) return false; - *window = reinterpret_cast<HWND>(StringToInt64(v[2])); + *window = reinterpret_cast<HWND>(base::StringToInt64(v[2])); return true; } diff --git a/chrome/browser/views/autofill_profiles_view_win.cc b/chrome/browser/views/autofill_profiles_view_win.cc index ffd477e..7b05966 100644 --- a/chrome/browser/views/autofill_profiles_view_win.cc +++ b/chrome/browser/views/autofill_profiles_view_win.cc @@ -1050,7 +1050,8 @@ void AutoFillProfilesView::EditableSetViewContents::InitCreditCardFields( combo_box_billing_ = new views::Combobox(billing_model_); combo_box_billing_->set_listener(this); int billing_id = -1; - if (StringToInt(temporary_info_.credit_card.billing_address(), &billing_id)) + if (base::StringToInt(temporary_info_.credit_card.billing_address(), + &billing_id)) combo_box_billing_->SetSelectedItem(billing_model_->GetIndex(billing_id)); billing_model_->UsedWithComboBox(combo_box_billing_); diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index d1a2d79..1860d6d 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -213,7 +213,7 @@ bool Extension::GenerateId(const std::string& input, std::string* output) { SHA256_Update(&ctx, ubuf, input.length()); uint8 hash[Extension::kIdSize]; SHA256_End(&ctx, hash, NULL, sizeof(hash)); - *output = StringToLowerASCII(HexEncode(hash, sizeof(hash))); + *output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); ConvertHexadecimalToIDAlphabet(output); return true; diff --git a/chrome/default_plugin/plugin_database_handler.cc b/chrome/default_plugin/plugin_database_handler.cc index ab79752..cc070754 100644 --- a/chrome/default_plugin/plugin_database_handler.cc +++ b/chrome/default_plugin/plugin_database_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,6 +14,7 @@ #include "base/file_util.h" #include "base/path_service.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" @@ -336,8 +337,9 @@ bool PluginDatabaseHandler::ReadPluginInfo(_xmlNode* plugin_node, plugin_download_url_for_display_node->children; if (url_for_display_val) { int url_for_display = 0; - StringToInt(reinterpret_cast<const char*>(url_for_display_val->content), - &url_for_display); + base::StringToInt( + reinterpret_cast<const char*>(url_for_display_val->content), + &url_for_display); if (url_for_display != 0) plugin_detail->download_url_for_display = true; } diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc index 3cbd522..08e9ae5 100644 --- a/chrome/installer/setup/setup_main.cc +++ b/chrome/installer/setup/setup_main.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,6 +16,7 @@ #include "base/process_util.h" #include "base/registry.h" #include "base/scoped_handle_win.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/win_util.h" @@ -521,7 +522,9 @@ bool HandleNonInstallCmdLineOptions(const CommandLine& cmd_line, // Launch the inactive user toast experiment. std::wstring flavor = cmd_line.GetSwitchValue(installer_util::switches::kInactiveUserToast); - dist->InactiveUserToastExperiment(StringToInt(flavor), + int flavor_int; + base::StringToInt(flavor, &flavor_int); + dist->InactiveUserToastExperiment(flavor_int, cmd_line.HasSwitch(installer_util::switches::kSystemLevelToast)); return true; } else if (cmd_line.HasSwitch(installer_util::switches::kSystemLevelToast)) { diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index 7b6150c..bbee52e 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -9,6 +9,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/registry.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/win_util.h" #include "chrome/common/result_codes.h" @@ -38,7 +39,7 @@ namespace { void CloseAllChromeProcesses() { for (int j = 0; j < 4; ++j) { std::wstring wnd_class(L"Chrome_WidgetWin_"); - wnd_class.append(IntToWString(j)); + wnd_class.append(base::IntToString16(j)); HWND window = FindWindowEx(NULL, NULL, wnd_class.c_str(), NULL); while (window) { HWND tmpWnd = window; diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index 265e1d3..c1085e4 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -20,6 +20,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/rand_util.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/task.h" #include "base/utf_string_conversions.h" @@ -298,7 +299,7 @@ void PrintSystemCUPS::EnumeratePrinters(PrinterList* printer_list) { const char* state = cupsGetOption(kCUPSPrinterStateOpt, printer.num_options, printer.options); if (state != NULL) - StringToInt(state, &printer_info.printer_status); + base::StringToInt(state, &printer_info.printer_status); // Store printer options. for (int opt_index = 0; opt_index < printer.num_options; opt_index++) { @@ -467,7 +468,7 @@ std::string PrintSystem::GenerateProxyId() { // unique for this user. Rand may return the same number. We'll need to change // this in the future. std::string id("CP_PROXY_"); - id += Uint64ToString(base::RandUint64()); + id += base::Uint64ToString(base::RandUint64()); return id; } diff --git a/chrome/test/chrome_process_util_mac.cc b/chrome/test/chrome_process_util_mac.cc index d920735..21e8746 100644 --- a/chrome/test/chrome_process_util_mac.cc +++ b/chrome/test/chrome_process_util_mac.cc @@ -9,6 +9,7 @@ #include "base/command_line.h" #include "base/process_util.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" MacChromeProcessInfoList GetRunningMacProcessInfo( @@ -45,9 +46,11 @@ MacChromeProcessInfoList GetRunningMacProcessInfo( SplitString(line, ' ', &values); if (values.size() == 3) { MacChromeProcessInfo proc_info; - proc_info.pid = StringToInt(values[0]); - proc_info.rsz_in_kb = StringToInt(values[1]); - proc_info.vsz_in_kb = StringToInt(values[2]); + int pid; + base::StringToInt(values[0], &pid); + proc_info.pid = pid; + base::StringToInt(values[1], &proc_info.rsz_in_kb); + base::StringToInt(values[2], &proc_info.vsz_in_kb); if (proc_info.pid && proc_info.rsz_in_kb && proc_info.vsz_in_kb) result.push_back(proc_info); } diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.cc b/chrome/test/mini_installer_test/chrome_mini_installer.cc index 931fb52..3bbe078 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.cc +++ b/chrome/test/mini_installer_test/chrome_mini_installer.cc @@ -9,6 +9,7 @@ #include "base/platform_thread.h" #include "base/process_util.h" #include "base/registry.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_constants.h" @@ -633,10 +634,13 @@ void ChromeMiniInstaller::LaunchBrowser(const std::wstring& launch_path, bool ChromeMiniInstaller::VerifyOverInstall( const std::wstring& value_before_overinstall, const std::wstring& value_after_overinstall) { - int64 reg_key_value_before_overinstall = StringToInt64( - value_before_overinstall); - int64 reg_key_value_after_overinstall = StringToInt64( - value_after_overinstall); + int64 reg_key_value_before_overinstall; + base::StringToInt64(value_before_overinstall, + ®_key_value_before_overinstall); + int64 reg_key_value_after_overinstall; + base::StringToInt64(value_after_overinstall, + ®_key_value_after_overinstall); + // Compare to see if the version is less. printf("Reg Key value before overinstall is%ls\n", value_before_overinstall.c_str()); diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc index 58ac2dd..76c32fe 100644 --- a/chrome/test/pyautolib/pyautolib.cc +++ b/chrome/test/pyautolib/pyautolib.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/scoped_ptr.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/test/automation/extension_proxy.h" @@ -10,6 +11,11 @@ #include "chrome/test/pyautolib/pyautolib.h" #include "googleurl/src/gurl.h" +static int64 StringToId(const std::wstring& str) { + int64 id; + base::StringToInt64(WideToUTF8(str), &id); + return id; +} // PyUITestSuiteBase PyUITestSuiteBase::PyUITestSuiteBase(int argc, char** argv) @@ -209,28 +215,27 @@ std::string PyUITestBase::_GetBookmarksAsJSON() { } bool PyUITestBase::AddBookmarkGroup(std::wstring& parent_id, int index, - std::wstring& title) { + std::wstring& title) { scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(0); // Window doesn't matter. EXPECT_TRUE(browser_proxy.get()); if (!browser_proxy.get()) return false; - return browser_proxy->AddBookmarkGroup(StringToInt64(WideToUTF16(parent_id)), - index, title); + return browser_proxy->AddBookmarkGroup(StringToId(parent_id), index, title); } bool PyUITestBase::AddBookmarkURL(std::wstring& parent_id, int index, - std::wstring& title, std::wstring& url) { + std::wstring& title, std::wstring& url) { scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(0); // Window doesn't matter. EXPECT_TRUE(browser_proxy.get()); if (!browser_proxy.get()) return false; - return browser_proxy->AddBookmarkURL(StringToInt64(WideToUTF16(parent_id)), + return browser_proxy->AddBookmarkURL(StringToId(parent_id), index, title, - GURL(WideToUTF16(url))); + GURL(WideToUTF8(url))); } bool PyUITestBase::ReparentBookmark( @@ -241,10 +246,9 @@ bool PyUITestBase::ReparentBookmark( if (!browser_proxy.get()) return false; - return browser_proxy->ReparentBookmark( - StringToInt64(WideToUTF16(id)), - StringToInt64(WideToUTF16(new_parent_id)), - index); + return browser_proxy->ReparentBookmark(StringToId(id), + StringToId(new_parent_id), + index); } bool PyUITestBase::SetBookmarkTitle(std::wstring& id, std::wstring& title) { @@ -254,8 +258,7 @@ bool PyUITestBase::SetBookmarkTitle(std::wstring& id, std::wstring& title) { if (!browser_proxy.get()) return false; - return browser_proxy->SetBookmarkTitle(StringToInt64(WideToUTF16(id)), - title); + return browser_proxy->SetBookmarkTitle(StringToId(id), title); } bool PyUITestBase::SetBookmarkURL(std::wstring& id, std::wstring& url) { @@ -265,8 +268,7 @@ bool PyUITestBase::SetBookmarkURL(std::wstring& id, std::wstring& url) { if (!browser_proxy.get()) return false; - return browser_proxy->SetBookmarkURL(StringToInt64(WideToUTF16(id)), - GURL(WideToUTF16(url))); + return browser_proxy->SetBookmarkURL(StringToId(id), GURL(WideToUTF8(url))); } bool PyUITestBase::RemoveBookmark(std::wstring& id) { @@ -276,7 +278,7 @@ bool PyUITestBase::RemoveBookmark(std::wstring& id) { if (!browser_proxy.get()) return false; - return browser_proxy->RemoveBookmark(StringToInt64(WideToUTF16(id))); + return browser_proxy->RemoveBookmark(StringToId(id)); } scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) { @@ -284,7 +286,7 @@ scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) { } std::string PyUITestBase::_SendJSONRequest(int window_index, - std::string& request) { + std::string& request) { scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(window_index); EXPECT_TRUE(browser_proxy.get()); diff --git a/chrome/test/ui/ui_test_suite.cc b/chrome/test/ui/ui_test_suite.cc index b74593d..5ba7f1f 100644 --- a/chrome/test/ui/ui_test_suite.cc +++ b/chrome/test/ui/ui_test_suite.cc @@ -63,12 +63,12 @@ void UITestSuite::Initialize() { std::wstring batch_count_str = parsed_command_line.GetSwitchValue(UITestSuite::kBatchCount); if (!batch_count_str.empty()) { - batch_count = StringToInt(WideToUTF16Hack(batch_count_str)); + base::StringToInt(WideToUTF16Hack(batch_count_str), &batch_count); } std::wstring batch_index_str = parsed_command_line.GetSwitchValue(UITestSuite::kBatchIndex); if (!batch_index_str.empty()) { - batch_index = StringToInt(WideToUTF16Hack(batch_index_str)); + base::StringToInt(WideToUTF16Hack(batch_index_str), &batch_index); } if (batch_count > 0 && batch_index >= 0 && batch_index < batch_count) { // Running UI test in parallel. Gtest supports running tests in shards, diff --git a/chrome_frame/chrome_tab.cc b/chrome_frame/chrome_tab.cc index 002d700..4f264a5 100644 --- a/chrome_frame/chrome_tab.cc +++ b/chrome_frame/chrome_tab.cc @@ -18,6 +18,7 @@ #include "base/logging_win.h" #include "base/path_service.h" #include "base/registry.h" +#include "base/string_number_conversions.h" #include "base/string_piece.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" @@ -99,7 +100,7 @@ class ChromeTabModule : public CAtlDllModuleT<ChromeTabModule> { if (SUCCEEDED(hr)) { SYSTEMTIME local_time; ::GetSystemTime(&local_time); - std::string hex(HexEncode(&local_time, sizeof(local_time))); + std::string hex(base::HexEncode(&local_time, sizeof(local_time))); base::StringPiece sp_hex(hex); hr = registrar->AddReplacement(L"SYSTIME", base::SysNativeMBToWide(sp_hex).c_str()); diff --git a/chrome_frame/protocol_sink_wrap.cc b/chrome_frame/protocol_sink_wrap.cc index 0c9a4ea..05b092d 100644 --- a/chrome_frame/protocol_sink_wrap.cc +++ b/chrome_frame/protocol_sink_wrap.cc @@ -189,7 +189,9 @@ ScopedComPtr<IBindCtx> BindCtxFromIBindInfo(IInternetBindInfo* bind_info) { bind_info->GetBindString(BINDSTRING_PTR_BIND_CONTEXT, &bind_ctx_string, 1, &count); if (bind_ctx_string) { - IBindCtx* pbc = reinterpret_cast<IBindCtx*>(StringToInt(bind_ctx_string)); + int bind_ctx_int; + base::StringToInt(bind_ctx_string, &bind_ctx_int); + IBindCtx* pbc = reinterpret_cast<IBindCtx*>(bind_ctx_int); bind_ctx.Attach(pbc); CoTaskMemFree(bind_ctx_string); } diff --git a/chrome_frame/test/mock_ie_event_sink_test.h b/chrome_frame/test/mock_ie_event_sink_test.h index e751073..73e8778 100644 --- a/chrome_frame/test/mock_ie_event_sink_test.h +++ b/chrome_frame/test/mock_ie_event_sink_test.h @@ -9,6 +9,7 @@ #include <atlcom.h> #include <string> +#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "chrome_frame/test/chrome_frame_test_utils.h" #include "chrome_frame/test/ie_event_sink.h" @@ -213,7 +214,7 @@ class MockIEEventSinkTest { DCHECK_LT(index, 5); std::wstring base_name = L"anchor.html"; if (index > 0) - base_name += std::wstring(L"#a") + IntToWString(index); + base_name += std::wstring(L"#a") + base::IntToString16(index); return GetTestUrl(base_name); } diff --git a/chrome_frame/test/test_server.cc b/chrome_frame/test/test_server.cc index 8f0910d..623a044 100644 --- a/chrome_frame/test/test_server.cc +++ b/chrome_frame/test/test_server.cc @@ -4,6 +4,7 @@ #include "base/logging.h" #include "base/registry.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -44,8 +45,10 @@ void Request::ParseHeaders(const std::string& headers) { "\r\n"); while (it.GetNext()) { if (LowerCaseEqualsASCII(it.name(), "content-length")) { - content_length_ = StringToInt(it.values().c_str()); - break; + int int_content_length; + base::StringToInt(it.values().c_str(), &int_content_length); + content_length_ = int_content_length; + break; } } } @@ -362,4 +365,4 @@ void ConfigurableConnection::SendWithOptions(const std::string& headers, options.timeout_); } -} // namespace test_server
\ No newline at end of file +} // namespace test_server diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc index 6c1e33e..3cce0cd 100644 --- a/chrome_frame/utils.cc +++ b/chrome_frame/utils.cc @@ -16,6 +16,7 @@ #include "base/scoped_bstr_win.h" #include "base/scoped_comptr_win.h" #include "base/scoped_variant_win.h" +#include "base/string_number_conversions.h" #include "base/string_tokenizer.h" #include "base/string_util.h" #include "base/thread_local.h" @@ -1070,7 +1071,7 @@ int GetHttpResponseStatusFromBinding(IBinding* binding) { DWORD reserved = 0; if (SUCCEEDED(info->QueryInfo(HTTP_QUERY_STATUS_CODE, status, &buf_size, &flags, &reserved))) { - http_status = StringToInt(status); + base::StringToInt(status, &http_status); } else { NOTREACHED() << "Failed to get HTTP status"; } diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 6d77eb1..d14a13f 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -199,7 +199,7 @@ GURL UpgradeUrlToHttps(const GURL& original_url) { // new_sheme and new_port need to be in scope here because GURL::Replacements // references the memory contained by them directly. const std::string new_scheme = "https"; - const std::string new_port = IntToString(443); + const std::string new_port = base::IntToString(443); replacements.SetSchemeStr(new_scheme); replacements.SetPortStr(new_port); return original_url.ReplaceComponents(replacements); diff --git a/net/tools/dump_cache/upgrade.cc b/net/tools/dump_cache/upgrade.cc index 60099b2..0d6d5e4 100644 --- a/net/tools/dump_cache/upgrade.cc +++ b/net/tools/dump_cache/upgrade.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/scoped_ptr.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/thread.h" #include "googleurl/src/gurl.h" @@ -883,7 +884,7 @@ void SlaveSM::Fail() { HANDLE CreateServer(std::wstring* pipe_number) { std::wstring pipe_name(kPipePrefix); srand(static_cast<int>(base::Time::Now().ToInternalValue())); - *pipe_number = IntToWString(rand()); + *pipe_number = base::IntToString16(rand()); pipe_name.append(*pipe_number); DWORD mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | diff --git a/webkit/glue/plugins/test/plugin_windowless_test.cc b/webkit/glue/plugins/test/plugin_windowless_test.cc index c47c1d7..aa6a9d7 100644 --- a/webkit/glue/plugins/test/plugin_windowless_test.cc +++ b/webkit/glue/plugins/test/plugin_windowless_test.cc @@ -1,8 +1,9 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #define STRSAFE_NO_DEPRECATE +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "webkit/glue/plugins/test/plugin_windowless_test.h" #include "webkit/glue/plugins/test/plugin_client.h" @@ -151,9 +152,9 @@ void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) { #if defined(OS_MACOSX) std::string StringForPoint(int x, int y) { std::string point_string("("); - point_string.append(IntToString(x)); + point_string.append(base::IntToString(x)); point_string.append(", "); - point_string.append(IntToString(y)); + point_string.append(base::IntToString(y)); point_string.append(")"); return point_string; } |