diff options
Diffstat (limited to 'chrome')
8 files changed, 50 insertions, 23 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc index 4006b29..5265666 100644 --- a/chrome/browser/autocomplete_history_manager.cc +++ b/chrome/browser/autocomplete_history_manager.cc @@ -19,6 +19,7 @@ #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; @@ -63,26 +64,32 @@ bool IsSSN(const string16& text) { return false; int area; - if (!base::StringToInt(number_string.begin(), - number_string.begin() + 3, - &area)) + if (!base::StringToInt(StringPiece16(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(number_string.begin() + 3, - number_string.begin() + 5, - &group) || group == 0) + if (!base::StringToInt(StringPiece16(number_string.begin() + 3, + number_string.begin() + 5), + &group) + || group == 0) { return false; + } int serial; - if (!base::StringToInt(number_string.begin() + 5, - number_string.begin() + 9, - &serial) || serial == 0) + if (!base::StringToInt(StringPiece16(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 6e2d98d..699dbc5 100644 --- a/chrome/browser/component_updater/component_updater_service.cc +++ b/chrome/browser/component_updater/component_updater_service.cc @@ -15,6 +15,7 @@ #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" @@ -74,10 +75,13 @@ 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(hexstr.begin() + i, hexstr.begin() + i + 1, &val)) + if (base::HexStringToInt(base::StringPiece(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 bb70fc7..c5da03c 100644 --- a/chrome/browser/history/text_database.cc +++ b/chrome/browser/history/text_database.cc @@ -111,9 +111,14 @@ 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.begin(), suffix.begin() + 4, &year); - base::StringToInt(suffix.begin() + 5, suffix.begin() + 7, &month); + base::StringToInt(suffix.substr(0, 4), &year); + base::StringToInt(suffix.substr(5, 2), &month); return year * 100 + month; } diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc index d71e788..4b11f54 100644 --- a/chrome/browser/profiles/profile_info_cache.cc +++ b/chrome/browser/profiles/profile_info_cache.cc @@ -13,6 +13,7 @@ #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" @@ -681,8 +682,9 @@ bool ProfileInfoCache::IsDefaultAvatarIconUrl(const std::string& url, return false; int int_value = -1; - if (base::StringToInt(url.begin() + strlen(kDefaultUrlPrefix), - url.end(), + if (base::StringToInt(base::StringPiece(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 be48a4e..22412cb2 100644 --- a/chrome/browser/safe_browsing/filter_false_positive_perftest.cc +++ b/chrome/browser/safe_browsing/filter_false_positive_perftest.cc @@ -64,6 +64,7 @@ #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" @@ -242,7 +243,8 @@ void CalculateBloomFilterFalsePositives( if (use_weights) { std::string::size_type pos = url.find_last_of(","); if (pos != std::string::npos) { - base::StringToInt(url.begin() + pos + 1, url.end(), &weight); + base::StringToInt(base::StringPiece(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 976c414..05dfb39 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -12,6 +12,7 @@ #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" @@ -467,8 +468,9 @@ 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(command.begin() + colon_index + 1, - command.end(), + bool result = base::StringToInt(base::StringPiece(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 4b790f0..9c1623a 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -17,6 +17,7 @@ #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" @@ -79,10 +80,13 @@ const char kDefaultContentSecurityPolicy[] = static void ConvertHexadecimalToIDAlphabet(std::string* id) { for (size_t i = 0; i < id->size(); ++i) { int val; - if (base::HexStringToInt(id->begin() + i, id->begin() + i + 1, &val)) + if (base::HexStringToInt(base::StringPiece(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 31401ea..e1f284e 100644 --- a/chrome/test/perf/page_cycler_test.cc +++ b/chrome/test/perf/page_cycler_test.cc @@ -9,6 +9,7 @@ #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" @@ -331,8 +332,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(timings.begin() + pos, - timings.begin() + new_pos, + if (!base::StringToInt(base::StringPiece(timings.begin() + pos, + timings.begin() + new_pos), &time)) { LOG(ERROR) << "Invalid time reported: " << time_str; return true; |