diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-18 21:31:07 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-18 21:31:07 +0000 |
commit | d25fc23b5f78a579d534fb1d51f4e45a767ff2d8 (patch) | |
tree | 71a91ce2cea378cf20078b8e2bda1f4dae448c14 | |
parent | ce87e24351c86bc40b32dca51fe2ebbabc603b1a (diff) | |
download | chromium_src-d25fc23b5f78a579d534fb1d51f4e45a767ff2d8.zip chromium_src-d25fc23b5f78a579d534fb1d51f4e45a767ff2d8.tar.gz chromium_src-d25fc23b5f78a579d534fb1d51f4e45a767ff2d8.tar.bz2 |
Revert 114944 - Standardize StringToInt{,64} interface.
Revert due to compile breakage on ChromeOS.
These changes address issue #106655. All variants of StringToInt have been
converted to use the StringPiece class. One instance of conversion, in
chrome/browser/history/text_database.cc, required copying an underlying
string. This is because the string type in question could use 8 or 16
bit characters depending on the OS type, and because StringPiece is not
implemented as a template, the code cannot specify whether to create a
StringPiece or StringPiece16. This should be remedied in a future CL.
R=erikwright@chromium.org
BUG=106655
TEST=
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=114929
Review URL: http://codereview.chromium.org/8921006
TBR=tedvessenes@gmail.com
Review URL: http://codereview.chromium.org/8990002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114945 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 298 insertions, 156 deletions
@@ -141,7 +141,6 @@ Naveen Bobbili <qghc36@motorola.com> Ravi Phaneendra Kasibhatla <ravi.kasibhatla@motorola.com> Rosen Dash <nqk836@motorola.com> Parag Radke <nrqv63@motorola.com> -Ted Vessenes <tedvessenes@gmail.com> Yair Yogev <progame@gmail.com> Chandra Shekar Vallala <brk376@motorola.com> Patrasciuc Sorin Cristian <cristian.patrasciuc@gmail.com> diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm index 2ba1a30..66fbf11 100644 --- a/base/mac/mac_util.mm +++ b/base/mac/mac_util.mm @@ -14,7 +14,6 @@ #include "base/mac/scoped_cftyperef.h" #include "base/memory/scoped_nsobject.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/sys_string_conversions.h" namespace base { @@ -522,9 +521,7 @@ int DarwinMajorVersionInternal() { int darwin_major_version = 0; char* dot = strchr(uname_info.release, '.'); if (dot) { - if (!base::StringToInt(base::StringPiece(uname_info.release, - dot - uname_info.release), - &darwin_major_version)) { + if (!base::StringToInt(uname_info.release, dot, &darwin_major_version)) { dot = NULL; } } diff --git a/base/string_number_conversions.cc b/base/string_number_conversions.cc index 1d82c5d..54eca17 100644 --- a/base/string_number_conversions.cc +++ b/base/string_number_conversions.cc @@ -292,6 +292,24 @@ class BaseIteratorRangeToNumberTraits { static const int kBase = BASE; }; +typedef BaseIteratorRangeToNumberTraits<std::string::const_iterator, int, 10> + IteratorRangeToIntTraits; +typedef BaseIteratorRangeToNumberTraits<string16::const_iterator, int, 10> + WideIteratorRangeToIntTraits; +typedef BaseIteratorRangeToNumberTraits<std::string::const_iterator, int64, 10> + IteratorRangeToInt64Traits; +typedef BaseIteratorRangeToNumberTraits<string16::const_iterator, int64, 10> + WideIteratorRangeToInt64Traits; + +typedef BaseIteratorRangeToNumberTraits<const char*, int, 10> + CharBufferToIntTraits; +typedef BaseIteratorRangeToNumberTraits<const char16*, int, 10> + WideCharBufferToIntTraits; +typedef BaseIteratorRangeToNumberTraits<const char*, int64, 10> + CharBufferToInt64Traits; +typedef BaseIteratorRangeToNumberTraits<const char16*, int64, 10> + WideCharBufferToInt64Traits; + template<typename ITERATOR> class BaseHexIteratorRangeToIntTraits : public BaseIteratorRangeToNumberTraits<ITERATOR, int, 16> { @@ -302,8 +320,10 @@ class BaseHexIteratorRangeToIntTraits } }; -typedef BaseHexIteratorRangeToIntTraits<StringPiece::const_iterator> +typedef BaseHexIteratorRangeToIntTraits<std::string::const_iterator> HexIteratorRangeToIntTraits; +typedef BaseHexIteratorRangeToIntTraits<const char*> + HexCharBufferToIntTraits; template<typename STR> bool HexStringToBytesT(const STR& input, std::vector<uint8>* output) { @@ -322,30 +342,6 @@ bool HexStringToBytesT(const STR& input, std::vector<uint8>* output) { return true; } -template <typename VALUE, int BASE> -class StringPieceToNumberTraits - : public BaseIteratorRangeToNumberTraits<StringPiece::const_iterator, - VALUE, - BASE> {}; - -template <typename VALUE> -bool StringToIntImpl(const StringPiece& input, VALUE* output) { - return IteratorRangeToNumber<StringPieceToNumberTraits<VALUE, 10> >::Invoke( - input.begin(), input.end(), output); -} - -template <typename VALUE, int BASE> -class StringPiece16ToNumberTraits - : public BaseIteratorRangeToNumberTraits<StringPiece16::const_iterator, - VALUE, - BASE> {}; - -template <typename VALUE> -bool String16ToIntImpl(const StringPiece16& input, VALUE* output) { - return IteratorRangeToNumber<StringPiece16ToNumberTraits<VALUE, 10> >::Invoke( - input.begin(), input.end(), output); -} - } // namespace std::string IntToString(int value) { @@ -394,22 +390,91 @@ std::string DoubleToString(double value) { return std::string(buffer); } -bool StringToInt(const StringPiece& input, int* output) { - return StringToIntImpl(input, output); +bool StringToInt(const std::string& input, int* output) { + return IteratorRangeToNumber<IteratorRangeToIntTraits>::Invoke(input.begin(), + input.end(), + output); +} + +bool StringToInt(std::string::const_iterator begin, + std::string::const_iterator end, + int* output) { + return IteratorRangeToNumber<IteratorRangeToIntTraits>::Invoke(begin, + end, + output); +} + +#if !defined(STD_STRING_ITERATOR_IS_CHAR_POINTER) +bool StringToInt(const char* begin, const char* end, int* output) { + return IteratorRangeToNumber<CharBufferToIntTraits>::Invoke(begin, + end, + output); +} +#endif + +bool StringToInt(const string16& input, int* output) { + return IteratorRangeToNumber<WideIteratorRangeToIntTraits>::Invoke( + input.begin(), input.end(), output); +} + +bool StringToInt(string16::const_iterator begin, + string16::const_iterator end, + int* output) { + return IteratorRangeToNumber<WideIteratorRangeToIntTraits>::Invoke(begin, + end, + output); +} + +#if !defined(BASE_STRING16_ITERATOR_IS_CHAR16_POINTER) +bool StringToInt(const char16* begin, const char16* end, int* output) { + return IteratorRangeToNumber<WideCharBufferToIntTraits>::Invoke(begin, + end, + output); +} +#endif + +bool StringToInt64(const std::string& input, int64* output) { + return IteratorRangeToNumber<IteratorRangeToInt64Traits>::Invoke( + input.begin(), input.end(), output); } -bool StringToInt(const StringPiece16& input, int* output) { - return String16ToIntImpl(input, output); +bool StringToInt64(std::string::const_iterator begin, + std::string::const_iterator end, + int64* output) { + return IteratorRangeToNumber<IteratorRangeToInt64Traits>::Invoke(begin, + end, + output); } -bool StringToInt64(const StringPiece& input, int64* output) { - return StringToIntImpl(input, output); +#if !defined(STD_STRING_ITERATOR_IS_CHAR_POINTER) +bool StringToInt64(const char* begin, const char* end, int64* output) { + return IteratorRangeToNumber<CharBufferToInt64Traits>::Invoke(begin, + end, + output); } +#endif -bool StringToInt64(const StringPiece16& input, int64* output) { - return String16ToIntImpl(input, output); +bool StringToInt64(const string16& input, int64* output) { + return IteratorRangeToNumber<WideIteratorRangeToInt64Traits>::Invoke( + input.begin(), input.end(), output); } +bool StringToInt64(string16::const_iterator begin, + string16::const_iterator end, + int64* output) { + return IteratorRangeToNumber<WideIteratorRangeToInt64Traits>::Invoke(begin, + end, + output); +} + +#if !defined(BASE_STRING16_ITERATOR_IS_CHAR16_POINTER) +bool StringToInt64(const char16* begin, const char16* end, int64* output) { + return IteratorRangeToNumber<WideCharBufferToInt64Traits>::Invoke(begin, + end, + output); +} +#endif + bool StringToDouble(const std::string& input, double* output) { errno = 0; // Thread-safe? It is on at least Mac, Linux, and Windows. char* endptr = NULL; @@ -452,11 +517,27 @@ std::string HexEncode(const void* bytes, size_t size) { return ret; } -bool HexStringToInt(const StringPiece& input, int* output) { +bool HexStringToInt(const std::string& input, int* output) { return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke( input.begin(), input.end(), output); } +bool HexStringToInt(std::string::const_iterator begin, + std::string::const_iterator end, + int* output) { + return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke(begin, + end, + output); +} + +#if !defined(STD_STRING_ITERATOR_IS_CHAR_POINTER) +bool HexStringToInt(const char* begin, const char* end, int* output) { + return IteratorRangeToNumber<HexCharBufferToIntTraits>::Invoke(begin, + end, + output); +} +#endif + bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { return HexStringToBytesT(input, output); } diff --git a/base/string_number_conversions.h b/base/string_number_conversions.h index 8dc7942..6cf6a76 100644 --- a/base/string_number_conversions.h +++ b/base/string_number_conversions.h @@ -10,7 +10,6 @@ #include "base/base_export.h" #include "base/basictypes.h" -#include "base/string_piece.h" #include "base/string16.h" // ---------------------------------------------------------------------------- @@ -59,10 +58,32 @@ BASE_EXPORT std::string DoubleToString(double value); // - 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. -BASE_EXPORT bool StringToInt(const StringPiece& input, int* output); -BASE_EXPORT bool StringToInt(const StringPiece16& input, int* output); -BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output); -BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output); +BASE_EXPORT bool StringToInt(const std::string& input, int* output); +BASE_EXPORT bool StringToInt(std::string::const_iterator begin, + std::string::const_iterator end, + int* output); +BASE_EXPORT bool StringToInt(const char* begin, const char* end, int* output); + +BASE_EXPORT bool StringToInt(const string16& input, int* output); +BASE_EXPORT bool StringToInt(string16::const_iterator begin, + string16::const_iterator end, + int* output); +BASE_EXPORT bool StringToInt(const char16* begin, const char16* end, + int* output); + +BASE_EXPORT bool StringToInt64(const std::string& input, int64* output); +BASE_EXPORT bool StringToInt64(std::string::const_iterator begin, + std::string::const_iterator end, + int64* output); +BASE_EXPORT bool StringToInt64(const char* begin, const char* end, + int64* output); + +BASE_EXPORT bool StringToInt64(const string16& input, int64* output); +BASE_EXPORT bool StringToInt64(string16::const_iterator begin, + string16::const_iterator end, + int64* output); +BASE_EXPORT bool StringToInt64(const char16* begin, const char16* end, + int64* output); // For floating-point conversions, only conversions of input strings in decimal // form are defined to work. Behavior with strings representing floating-point @@ -83,7 +104,12 @@ BASE_EXPORT bool StringToDouble(const std::string& input, double* output); BASE_EXPORT std::string HexEncode(const void* bytes, size_t size); // Best effort conversion, see StringToInt above for restrictions. -BASE_EXPORT bool HexStringToInt(const StringPiece& input, int* output); +BASE_EXPORT bool HexStringToInt(const std::string& input, int* output); +BASE_EXPORT bool HexStringToInt(std::string::const_iterator begin, + std::string::const_iterator end, + int* output); +BASE_EXPORT bool HexStringToInt(const char* begin, const char* end, + 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 diff --git a/base/string_number_conversions_unittest.cc b/base/string_number_conversions_unittest.cc index 438db07..1e5ff14 100644 --- a/base/string_number_conversions_unittest.cc +++ b/base/string_number_conversions_unittest.cc @@ -105,14 +105,34 @@ TEST(StringNumberConversionsTest, StringToInt) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + const char* ascii_chars = cases[i].input.c_str(); int output = 0; EXPECT_EQ(cases[i].success, StringToInt(cases[i].input, &output)); EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt(cases[i].input.begin(), + cases[i].input.end(), + &output)); + EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt( + ascii_chars, ascii_chars + cases[i].input.length(), &output)); + EXPECT_EQ(cases[i].output, output); string16 utf16_input = UTF8ToUTF16(cases[i].input); + const char16* utf16_chars = utf16_input.c_str(); output = 0; EXPECT_EQ(cases[i].success, StringToInt(utf16_input, &output)); EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt(utf16_input.begin(), + utf16_input.end(), + &output)); + EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt( + utf16_chars, utf16_chars + utf16_input.length(), &output)); + EXPECT_EQ(cases[i].output, output); } // One additional test to verify that conversion of numbers in strings with @@ -123,11 +143,26 @@ TEST(StringNumberConversionsTest, StringToInt) { int output; EXPECT_FALSE(StringToInt(input_string, &output)); EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt(input_string.begin(), input_string.end(), &output)); + EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt(input, input + arraysize(input), &output)); + EXPECT_EQ(6, output); string16 utf16_input = UTF8ToUTF16(input_string); + const char16* utf16_chars = utf16_input.c_str(); output = 0; EXPECT_FALSE(StringToInt(utf16_input, &output)); EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt(utf16_input.begin(), utf16_input.end(), &output)); + EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt(utf16_chars, + utf16_chars + utf16_input.length(), + &output)); + EXPECT_EQ(6, output); output = 0; const char16 negative_wide_input[] = { 0xFF4D, '4', '2', 0}; @@ -175,14 +210,34 @@ TEST(StringNumberConversionsTest, StringToInt64) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + const char* ascii_chars = cases[i].input.c_str(); int64 output = 0; EXPECT_EQ(cases[i].success, StringToInt64(cases[i].input, &output)); EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt64(cases[i].input.begin(), + cases[i].input.end(), + &output)); + EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt64( + ascii_chars, ascii_chars + cases[i].input.length(), &output)); + EXPECT_EQ(cases[i].output, output); string16 utf16_input = UTF8ToUTF16(cases[i].input); + const char16* utf16_chars = utf16_input.c_str(); output = 0; EXPECT_EQ(cases[i].success, StringToInt64(utf16_input, &output)); EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt64(utf16_input.begin(), + utf16_input.end(), + &output)); + EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, StringToInt64( + utf16_chars, utf16_chars + utf16_input.length(), &output)); + EXPECT_EQ(cases[i].output, output); } // One additional test to verify that conversion of numbers in strings with @@ -193,11 +248,28 @@ TEST(StringNumberConversionsTest, StringToInt64) { int64 output; EXPECT_FALSE(StringToInt64(input_string, &output)); EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt64(input_string.begin(), + input_string.end(), + &output)); + EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt64(input, input + arraysize(input), &output)); + EXPECT_EQ(6, output); string16 utf16_input = UTF8ToUTF16(input_string); + const char16* utf16_chars = utf16_input.c_str(); output = 0; EXPECT_FALSE(StringToInt64(utf16_input, &output)); EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt64(utf16_input.begin(), utf16_input.end(), &output)); + EXPECT_EQ(6, output); + output = 0; + EXPECT_FALSE(StringToInt64(utf16_chars, + utf16_chars + utf16_input.length(), + &output)); + EXPECT_EQ(6, output); } TEST(StringNumberConversionsTest, HexStringToInt) { @@ -238,9 +310,19 @@ TEST(StringNumberConversionsTest, HexStringToInt) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + const char* ascii_chars = cases[i].input.c_str(); int output = 0; EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input, &output)); EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, HexStringToInt(cases[i].input.begin(), + cases[i].input.end(), + &output)); + EXPECT_EQ(cases[i].output, output); + output = 0; + EXPECT_EQ(cases[i].success, HexStringToInt( + ascii_chars, ascii_chars + cases[i].input.length(), &output)); + EXPECT_EQ(cases[i].output, output); } // One additional test to verify that conversion of numbers in strings with // embedded NUL characters. The NUL and extra data after it should be @@ -250,6 +332,14 @@ TEST(StringNumberConversionsTest, HexStringToInt) { int output; EXPECT_FALSE(HexStringToInt(input_string, &output)); EXPECT_EQ(0xc0ffee, output); + output = 0; + EXPECT_FALSE(HexStringToInt(input_string.begin(), + input_string.end(), + &output)); + EXPECT_EQ(0xc0ffee, output); + output = 0; + EXPECT_FALSE(HexStringToInt(input, input + arraysize(input), &output)); + EXPECT_EQ(0xc0ffee, output); } TEST(StringNumberConversionsTest, HexStringToBytes) { diff --git a/base/string_piece.h b/base/string_piece.h index 5e420c1..278c7b6 100644 --- a/base/string_piece.h +++ b/base/string_piece.h @@ -60,10 +60,6 @@ class BASE_EXPORT StringPiece { : ptr_(str.data()), length_(str.size()) { } StringPiece(const char* offset, size_type len) : ptr_(offset), length_(len) { } - StringPiece(const std::string::const_iterator& begin, - const std::string::const_iterator& end) - : ptr_((end > begin) ? &(*begin) : NULL), - length_((end > begin) ? (size_type)(end - begin) : 0) { } // data() may return a pointer to a buffer with embedded NULs, and the // returned buffer may or may not be null terminated. Therefore it is @@ -201,10 +197,6 @@ class BASE_EXPORT StringPiece16 { : ptr_(str.data()), length_(str.size()) { } StringPiece16(const char16* offset, size_type len) : ptr_(offset), length_(len) { } - StringPiece16(const string16::const_iterator& begin, - const string16::const_iterator& end) - : ptr_((end > begin) ? &(*begin) : NULL), - length_((end > begin) ? (size_type)(end - begin) : 0) { } // data() may return a pointer to a buffer with embedded NULs, and the // returned buffer may or may not be null terminated. Therefore it is diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc index 5265666..4006b29 100644 --- a/chrome/browser/autocomplete_history_manager.cc +++ b/chrome/browser/autocomplete_history_manager.cc @@ -19,7 +19,6 @@ #include "content/browser/tab_contents/tab_contents.h" #include "webkit/forms/form_data.h" -using base::StringPiece16; using webkit::forms::FormData; using webkit::forms::FormField; @@ -64,32 +63,26 @@ bool IsSSN(const string16& text) { return false; int area; - if (!base::StringToInt(StringPiece16(number_string.begin(), - number_string.begin() + 3), - &area)) { + if (!base::StringToInt(number_string.begin(), + number_string.begin() + 3, + &area)) return false; - } if (area < 1 || area == 666 || - area >= 900) { + area >= 900) return false; - } int group; - if (!base::StringToInt(StringPiece16(number_string.begin() + 3, - number_string.begin() + 5), - &group) - || group == 0) { + if (!base::StringToInt(number_string.begin() + 3, + number_string.begin() + 5, + &group) || group == 0) return false; - } int serial; - if (!base::StringToInt(StringPiece16(number_string.begin() + 5, - number_string.begin() + 9), - &serial) - || serial == 0) { + if (!base::StringToInt(number_string.begin() + 5, + number_string.begin() + 9, + &serial) || serial == 0) return false; - } return true; } diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc index 699dbc5..6e2d98d 100644 --- a/chrome/browser/component_updater/component_updater_service.cc +++ b/chrome/browser/component_updater/component_updater_service.cc @@ -15,7 +15,6 @@ #include "base/memory/scoped_ptr.h" #include "base/stl_util.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/timer.h" @@ -75,13 +74,10 @@ static std::string HexStringToID(const std::string& hexstr) { std::string id; for (size_t i = 0; i < hexstr.size(); ++i) { int val; - if (base::HexStringToInt(base::StringPiece(hexstr.begin() + i, - hexstr.begin() + i + 1), - &val)) { + if (base::HexStringToInt(hexstr.begin() + i, hexstr.begin() + i + 1, &val)) id.append(1, val + 'a'); - } else { + else id.append(1, 'a'); - } } DCHECK(Extension::IdIsValid(id)); return id; diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc index c5da03c..bb70fc7 100644 --- a/chrome/browser/history/text_database.cc +++ b/chrome/browser/history/text_database.cc @@ -111,14 +111,9 @@ TextDatabase::DBIdent TextDatabase::FileNameToID(const FilePath& file_path) { return 0; } - // TODO: Once StringPiece supports a templated interface over the - // underlying string type, use it here instead of substr, since that - // will avoid needless string copies. StringPiece cannot be used - // right now because FilePath::StringType could use either 8 or 16 bit - // characters, depending on the OS. int year, month; - base::StringToInt(suffix.substr(0, 4), &year); - base::StringToInt(suffix.substr(5, 2), &month); + base::StringToInt(suffix.begin(), suffix.begin() + 4, &year); + base::StringToInt(suffix.begin() + 5, suffix.begin() + 7, &month); return year * 100 + month; } diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc index 4b11f54..d71e788 100644 --- a/chrome/browser/profiles/profile_info_cache.cc +++ b/chrome/browser/profiles/profile_info_cache.cc @@ -13,7 +13,6 @@ #include "base/rand_util.h" #include "base/stl_util.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -682,9 +681,8 @@ bool ProfileInfoCache::IsDefaultAvatarIconUrl(const std::string& url, return false; int int_value = -1; - if (base::StringToInt(base::StringPiece(url.begin() + - strlen(kDefaultUrlPrefix), - url.end()), + if (base::StringToInt(url.begin() + strlen(kDefaultUrlPrefix), + url.end(), &int_value)) { if (int_value < 0 || int_value >= static_cast<int>(kDefaultAvatarIconsCount)) diff --git a/chrome/browser/safe_browsing/filter_false_positive_perftest.cc b/chrome/browser/safe_browsing/filter_false_positive_perftest.cc index 22412cb2..be48a4e 100644 --- a/chrome/browser/safe_browsing/filter_false_positive_perftest.cc +++ b/chrome/browser/safe_browsing/filter_false_positive_perftest.cc @@ -64,7 +64,6 @@ #include "base/path_service.h" #include "base/rand_util.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_util.h" #include "base/time.h" #include "chrome/browser/safe_browsing/bloom_filter.h" @@ -243,8 +242,7 @@ void CalculateBloomFilterFalsePositives( if (use_weights) { std::string::size_type pos = url.find_last_of(","); if (pos != std::string::npos) { - base::StringToInt(base::StringPiece(url.begin() + pos + 1, url.end()), - &weight); + base::StringToInt(url.begin() + pos + 1, url.end(), &weight); url = url.substr(0, pos); } } diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 05dfb39..976c414 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -12,7 +12,6 @@ #include "base/i18n/rtl.h" #include "base/lazy_instance.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -468,9 +467,8 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { size_t colon_index = command.find(':'); if (colon_index != std::string::npos) { DCHECK(colon_index < command.size() - 1); - bool result = base::StringToInt(base::StringPiece(command.begin() + - colon_index + 1, - command.end()), + bool result = base::StringToInt(command.begin() + colon_index + 1, + command.end(), &element_index); command = command.substr(0, colon_index); DCHECK(result); diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 9c1623a..4b790f0 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -17,7 +17,6 @@ #include "base/stl_util.h" #include "base/string16.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -80,13 +79,10 @@ const char kDefaultContentSecurityPolicy[] = static void ConvertHexadecimalToIDAlphabet(std::string* id) { for (size_t i = 0; i < id->size(); ++i) { int val; - if (base::HexStringToInt(base::StringPiece(id->begin() + i, - id->begin() + i + 1), - &val)) { + if (base::HexStringToInt(id->begin() + i, id->begin() + i + 1, &val)) (*id)[i] = val + 'a'; - } else { + else (*id)[i] = 'a'; - } } } diff --git a/chrome/test/perf/page_cycler_test.cc b/chrome/test/perf/page_cycler_test.cc index e1f284e..31401ea 100644 --- a/chrome/test/perf/page_cycler_test.cc +++ b/chrome/test/perf/page_cycler_test.cc @@ -9,7 +9,6 @@ #include "base/path_service.h" #include "base/process_util.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/sys_string_conversions.h" #include "base/test/test_timeouts.h" #include "base/utf_string_conversions.h" @@ -332,8 +331,8 @@ static bool HasDatabaseErrors(const std::string timings) { new_pos = timings.find(',', pos); if (new_pos == std::string::npos) new_pos = timings.length(); - if (!base::StringToInt(base::StringPiece(timings.begin() + pos, - timings.begin() + new_pos), + if (!base::StringToInt(timings.begin() + pos, + timings.begin() + new_pos, &time)) { LOG(ERROR) << "Invalid time reported: " << time_str; return true; diff --git a/chrome_frame/test/test_server.cc b/chrome_frame/test/test_server.cc index cddcd2c..f2d7de3 100644 --- a/chrome_frame/test/test_server.cc +++ b/chrome_frame/test/test_server.cc @@ -9,7 +9,6 @@ #include "base/bind.h" #include "base/logging.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" @@ -50,8 +49,8 @@ void Request::ParseHeaders(const std::string& headers) { while (it.GetNext()) { if (LowerCaseEqualsASCII(it.name(), "content-length")) { int int_content_length; - base::StringToInt(base::StringPiece(it.values_begin(), - it.values_end()), + base::StringToInt(it.values_begin(), + it.values_end(), &int_content_length); content_length_ = int_content_length; break; diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc index 8610f83..9003109 100644 --- a/chrome_frame/utils.cc +++ b/chrome_frame/utils.cc @@ -16,7 +16,6 @@ #include "base/logging.h" #include "base/path_service.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_tokenizer.h" #include "base/string_util.h" #include "base/stringprintf.h" @@ -1555,9 +1554,7 @@ int GetXUaCompatibleDirective(const std::string& directive, char delimiter) { } int header_ie_version = 0; - if (!base::StringToInt(base::StringPiece(filter_begin + 2, - filter_end), - &header_ie_version) || + if (!base::StringToInt(filter_begin + 2, filter_end, &header_ie_version) || header_ie_version == 0) { // ensure it's not a sequence of 0's continue; } diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 180a905..7ae4363d 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1985,8 +1985,8 @@ void SetExplicitlyAllowedPorts(const std::string& allowed_ports) { if (i == size || allowed_ports[i] == kComma) { if (i > last) { int port; - base::StringToInt(base::StringPiece(allowed_ports.begin() + last, - allowed_ports.begin() + i), + base::StringToInt(allowed_ports.begin() + last, + allowed_ports.begin() + i, &port); ports.insert(port); } diff --git a/net/base/x509_cert_types.cc b/net/base/x509_cert_types.cc index 7578ccd..6beb3ec 100644 --- a/net/base/x509_cert_types.cc +++ b/net/base/x509_cert_types.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-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. @@ -20,7 +20,7 @@ namespace { // untouched otherwise. Returns the parsed integer. int ParseIntAndAdvance(const char** field, size_t field_len, bool* ok) { int result = 0; - *ok &= base::StringToInt(base::StringPiece(*field, field_len), &result); + *ok &= base::StringToInt(*field, *field + field_len, &result); *field += field_len; return result; } diff --git a/net/ftp/ftp_ctrl_response_buffer.cc b/net/ftp/ftp_ctrl_response_buffer.cc index 670c70d..4aeef1f 100644 --- a/net/ftp/ftp_ctrl_response_buffer.cc +++ b/net/ftp/ftp_ctrl_response_buffer.cc @@ -1,12 +1,11 @@ -// Copyright (c) 2011 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. +// Copyright (c) 2009 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. #include "net/ftp/ftp_ctrl_response_buffer.h" #include "base/logging.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" //#include "base/string_util.h" #include "net/base/net_errors.h" @@ -92,8 +91,7 @@ FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( ParsedLine result; if (line.length() >= 3) { - if (base::StringToInt(base::StringPiece(line.begin(), line.begin() + 3), - &result.status_code)) + if (base::StringToInt(line.begin(), line.begin() + 3, &result.status_code)) result.has_status_code = (100 <= result.status_code && result.status_code <= 599); if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { diff --git a/net/ftp/ftp_util.cc b/net/ftp/ftp_util.cc index f6bdf2f..553d513 100644 --- a/net/ftp/ftp_util.cc +++ b/net/ftp/ftp_util.cc @@ -12,7 +12,6 @@ #include "base/logging.h" #include "base/memory/singleton.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_split.h" #include "base/string_tokenizer.h" #include "base/string_util.h" @@ -22,8 +21,6 @@ #include "unicode/dtfmtsym.h" #include "unicode/uchar.h" -using base::StringPiece16; - // For examples of Unix<->VMS path conversions, see the unit test file. On VMS // a path looks differently depending on whether it's a file or directory. @@ -214,26 +211,26 @@ bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, if (!base::StringToInt(rest, &time_exploded.year)) { // Maybe it's time. Does it look like time (HH:MM)? if (rest.length() == 5 && rest[2] == ':') { - if (!base::StringToInt(StringPiece16(rest.begin(), rest.begin() + 2), - &time_exploded.hour)) { + if (!base::StringToInt(rest.begin(), + rest.begin() + 2, + &time_exploded.hour)) return false; - } - if (!base::StringToInt(StringPiece16(rest.begin() + 3, rest.begin() + 5), - &time_exploded.minute)) { + if (!base::StringToInt(rest.begin() + 3, + rest.begin() + 5, + &time_exploded.minute)) return false; - } } else if (rest.length() == 4 && rest[1] == ':') { // Sometimes it's just H:MM. - if (!base::StringToInt(StringPiece16(rest.begin(), rest.begin() + 1), - &time_exploded.hour)) { + if (!base::StringToInt(rest.begin(), + rest.begin() + 1, + &time_exploded.hour)) return false; - } - if (!base::StringToInt(StringPiece16(rest.begin() + 2, rest.begin() + 4), - &time_exploded.minute)) { + if (!base::StringToInt(rest.begin() + 2, + rest.begin() + 4, + &time_exploded.minute)) return false; - } } else { return false; } diff --git a/net/http/http_chunked_decoder.cc b/net/http/http_chunked_decoder.cc index 87f54640..d5b16dd 100644 --- a/net/http/http_chunked_decoder.cc +++ b/net/http/http_chunked_decoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 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. @@ -187,14 +187,12 @@ bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { // Be more restrictive than HexStringToInt; // don't allow inputs with leading "-", "+", "0x", "0X" - base::StringPiece chunk_size(start, len); - if (chunk_size.find_first_not_of("0123456789abcdefABCDEF") - != base::StringPiece::npos) { + if (base::StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF") + != base::StringPiece::npos) return false; - } int parsed_number; - bool ok = base::HexStringToInt(chunk_size, &parsed_number); + bool ok = base::HexStringToInt(start, start + len, &parsed_number); if (ok && parsed_number >= 0) { *out = parsed_number; return true; diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index 98bd052..f249db8 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -15,13 +15,11 @@ #include "base/metrics/histogram.h" #include "base/pickle.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_util.h" #include "base/time.h" #include "net/base/escape.h" #include "net/http/http_util.h" -using base::StringPiece; using base::Time; using base::TimeDelta; @@ -700,7 +698,7 @@ void HttpResponseHeaders::ParseStatusLine( raw_headers_.push_back(' '); raw_headers_.append(code, p); raw_headers_.push_back(' '); - base::StringToInt(StringPiece(code, p), &response_code_); + base::StringToInt(code, p, &response_code_); // Skip whitespace. while (*p == ' ') @@ -1073,8 +1071,8 @@ bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { value.begin() + kMaxAgePrefixLen, kMaxAgePrefix)) { int64 seconds; - base::StringToInt64(StringPiece(value.begin() + kMaxAgePrefixLen, - value.end()), + base::StringToInt64(value.begin() + kMaxAgePrefixLen, + value.end(), &seconds); *result = TimeDelta::FromSeconds(seconds); return true; @@ -1252,8 +1250,8 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position, byte_range_resp_spec.begin() + minus_position; HttpUtil::TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); - bool ok = base::StringToInt64(StringPiece(first_byte_pos_begin, - first_byte_pos_end), + bool ok = base::StringToInt64(first_byte_pos_begin, + first_byte_pos_end, first_byte_position); // Obtain last-byte-pos. @@ -1263,8 +1261,8 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position, byte_range_resp_spec.end(); HttpUtil::TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); - ok &= base::StringToInt64(StringPiece(last_byte_pos_begin, - last_byte_pos_end), + ok &= base::StringToInt64(last_byte_pos_begin, + last_byte_pos_end, last_byte_position); if (!ok) { *first_byte_position = *last_byte_position = -1; @@ -1288,8 +1286,8 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position, if (LowerCaseEqualsASCII(instance_length_begin, instance_length_end, "*")) { return false; - } else if (!base::StringToInt64(StringPiece(instance_length_begin, - instance_length_end), + } else if (!base::StringToInt64(instance_length_begin, + instance_length_end, instance_length)) { *instance_length = -1; return false; diff --git a/net/proxy/proxy_bypass_rules.cc b/net/proxy/proxy_bypass_rules.cc index 1c0fd61..3d622a8 100644 --- a/net/proxy/proxy_bypass_rules.cc +++ b/net/proxy/proxy_bypass_rules.cc @@ -7,7 +7,6 @@ #include "base/stl_util.h" #include "base/stringprintf.h" #include "base/string_number_conversions.h" -#include "base/string_piece.h" #include "base/string_tokenizer.h" #include "base/string_util.h" #include "net/base/net_util.h" @@ -316,9 +315,7 @@ bool ProxyBypassRules::AddRuleFromStringInternal( host = raw; port = -1; if (pos_colon != std::string::npos) { - if (!base::StringToInt(base::StringPiece(raw.begin() + pos_colon + 1, - raw.end()), - &port) || + if (!base::StringToInt(raw.begin() + pos_colon + 1, raw.end(), &port) || (port < 0 || port > 0xFFFF)) { return false; // Port was invalid. } |