diff options
author | erikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-22 16:05:47 +0000 |
---|---|---|
committer | erikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-22 16:05:47 +0000 |
commit | c2750c67ca3a672018bac2dfb07628d079aafc8d (patch) | |
tree | 8bbff1c4c3aeb363e06734e91e172653e34737cc | |
parent | 213b99ad9d66e3c039bbb90c19d78603975c1be9 (diff) | |
download | chromium_src-c2750c67ca3a672018bac2dfb07628d079aafc8d.zip chromium_src-c2750c67ca3a672018bac2dfb07628d079aafc8d.tar.gz chromium_src-c2750c67ca3a672018bac2dfb07628d079aafc8d.tar.bz2 |
Update code that previously constructed strings from string iterators only to use StringToInt. These usages now pass the iterators directly to the new StringToInt overloads.
BUG=None
TEST=All
Review URL: http://codereview.chromium.org/3968001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63515 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 110 insertions, 72 deletions
diff --git a/base/sys_info_chromeos.cc b/base/sys_info_chromeos.cc index 1cd9fb6..fec2696 100644 --- a/base/sys_info_chromeos.cc +++ b/base/sys_info_chromeos.cc @@ -54,12 +54,18 @@ void SysInfo::ParseLsbRelease(const std::string& lsb_release, StringTokenizer tokenizer(version, "."); for (int i = 0; i < 3 && tokenizer.GetNext(); i++) { if (0 == i) { - StringToInt(tokenizer.token(), major_version); + StringToInt(tokenizer.token_begin(), + tokenizer.token_end(), + major_version); *minor_version = *bugfix_version = 0; } else if (1 == i) { - StringToInt(tokenizer.token(), minor_version); + StringToInt(tokenizer.token_begin(), + tokenizer.token_end(), + minor_version); } else { // 2 == i - StringToInt(tokenizer.token(), bugfix_version); + StringToInt(tokenizer.token_begin(), + tokenizer.token_end(), + bugfix_version); } } } diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc index b2c4d3c..2243bcb 100644 --- a/chrome/browser/autocomplete_history_manager.cc +++ b/chrome/browser/autocomplete_history_manager.cc @@ -31,8 +31,6 @@ const string16 kSSNSeparators = ASCIIToUTF16(" -"); bool IsSSN(const string16& text) { string16 number_string; RemoveChars(text, kSSNSeparators.c_str(), &number_string); - if (number_string.length() != 9 || !IsStringASCII(number_string)) - return false; // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = // serial number). The validation we do here is simply checking if the area, @@ -42,13 +40,13 @@ bool IsSSN(const string16& text) { // See: http://www.socialsecurity.gov/history/ssn/geocard.html // http://www.socialsecurity.gov/employer/stateweb.htm // http://www.socialsecurity.gov/employer/ssnvhighgroup.htm - - string16 area_string = number_string.substr(0, 3); - string16 group_string = number_string.substr(3, 2); - string16 serial_string = number_string.substr(5, 4); + if (number_string.length() != 9 || !IsStringASCII(number_string)) + return false; int area; - if (!base::StringToInt(area_string, &area)) + if (!base::StringToInt(number_string.begin(), + number_string.begin() + 3, + &area)) return false; if (area < 1 || area == 666 || @@ -57,11 +55,15 @@ bool IsSSN(const string16& text) { return false; int group; - if (!base::StringToInt(group_string, &group) || group == 0) + if (!base::StringToInt(number_string.begin() + 3, + number_string.begin() + 5, + &group) || group == 0) return false; int serial; - if (!base::StringToInt(serial_string, &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/chromeos/customization_document.cc b/chrome/browser/chromeos/customization_document.cc index b9a4f34..a9d438a 100644 --- a/chrome/browser/chromeos/customization_document.cc +++ b/chrome/browser/chromeos/customization_document.cc @@ -103,7 +103,9 @@ bool StartupCustomizationDocument::ParseFromJsonValue( if (!background_color_string.empty()) { if (background_color_string[0] == '#') { int background_int; - base::HexStringToInt(background_color_string.substr(1), &background_int); + base::HexStringToInt(background_color_string.begin() + 1, + background_color_string.end(), + &background_int); background_color_ = static_cast<SkColor>(0xff000000 | background_int); } else { // Literal color constants are not supported yet. diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc index 84367d3..60aa7fd 100644 --- a/chrome/browser/history/text_database.cc +++ b/chrome/browser/history/text_database.cc @@ -112,8 +112,8 @@ TextDatabase::DBIdent TextDatabase::FileNameToID(const FilePath& file_path) { } 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/safe_browsing/filter_false_positive_perftest.cc b/chrome/browser/safe_browsing/filter_false_positive_perftest.cc index f763b51c..eec1c2e 100644 --- a/chrome/browser/safe_browsing/filter_false_positive_perftest.cc +++ b/chrome/browser/safe_browsing/filter_false_positive_perftest.cc @@ -261,7 +261,7 @@ void CalculateBloomFilterFalsePositives( if (use_weights) { std::string::size_type pos = url.find_last_of(","); if (pos != std::string::npos) { - base::StringToInt(std::string(url, pos + 1), &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 ace8abb..fc36bf5 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -331,9 +331,10 @@ 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); - std::string index_str = command.substr(colon_index + 1); command = command.substr(0, colon_index); - bool result = base::StringToInt(index_str, &element_index); + bool result = base::StringToInt(command.begin() + colon_index + 1, + command.end(), + &element_index); DCHECK(result); } diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index fbb262f..e3254d8 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -64,7 +64,7 @@ const int kRSAKeySize = 1024; static void ConvertHexadecimalToIDAlphabet(std::string* id) { for (size_t i = 0; i < id->size(); ++i) { int val; - if (base::HexStringToInt(id->substr(i, 1), &val)) + if (base::HexStringToInt(id->begin() + i, id->begin() + i + 1, &val)) (*id)[i] = val + 'a'; else (*id)[i] = 'a'; diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index 7d0a5a2..082fc82 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -614,7 +614,8 @@ NPError WebPluginDelegatePepper::Device2DGetStateContext( // Return the least significant 8 characters (i.e. 4 bytes) // of the 32 character hexadecimal result as an int. int int_val; - base::HexStringToInt(hex_md5.substr(24), &int_val); + DCHECK_EQ(hex_md5.length(), 32u); + base::HexStringToInt(hex_md5.begin() + 24, hex_md5.end(), &int_val); *value = int_val; return NPERR_NO_ERROR; } diff --git a/chrome/test/page_cycler/page_cycler_test.cc b/chrome/test/page_cycler/page_cycler_test.cc index 1674869..7346489 100644 --- a/chrome/test/page_cycler/page_cycler_test.cc +++ b/chrome/test/page_cycler/page_cycler_test.cc @@ -366,8 +366,9 @@ static bool HasDatabaseErrors(const std::string timings) { new_pos = timings.find(',', pos); if (new_pos == std::string::npos) new_pos = timings.length(); - time_str = timings.substr(pos, new_pos - pos); - if (!base::StringToInt(time_str, &time)) { + 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 98792e2..a7c0822 100644 --- a/chrome_frame/test/test_server.cc +++ b/chrome_frame/test/test_server.cc @@ -48,7 +48,9 @@ void Request::ParseHeaders(const std::string& headers) { while (it.GetNext()) { if (LowerCaseEqualsASCII(it.name(), "content-length")) { int int_content_length; - base::StringToInt(it.values().c_str(), &int_content_length); + base::StringToInt(it.values().begin(), + it.values().end(), + &int_content_length); content_length_ = int_content_length; break; } diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 45dc60c..8f6b2af 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1676,10 +1676,11 @@ void SetExplicitlyAllowedPorts(const std::string& allowed_ports) { (allowed_ports[i] != kComma)) return; if (i == size || allowed_ports[i] == kComma) { - size_t length = i - last; - if (length > 0) { + if (i > last) { int port; - base::StringToInt(allowed_ports.substr(last, length), &port); + base::StringToInt(allowed_ports.begin() + last, + allowed_ports.begin() + i, + &port); ports.insert(port); } last = i + 1; diff --git a/net/base/transport_security_state.cc b/net/base/transport_security_state.cc index a0d2794..dc87c10 100644 --- a/net/base/transport_security_state.cc +++ b/net/base/transport_security_state.cc @@ -142,7 +142,9 @@ bool TransportSecurityState::ParseHeader(const std::string& value, case AFTER_MAX_AGE_EQUALS: if (IsAsciiWhitespace(*tokenizer.token_begin())) continue; - if (!base::StringToInt(tokenizer.token(), &max_age_candidate)) + if (!base::StringToInt(tokenizer.token_begin(), + tokenizer.token_end(), + &max_age_candidate)) return false; if (max_age_candidate < 0) return false; diff --git a/net/base/x509_certificate_openssl.cc b/net/base/x509_certificate_openssl.cc index 52d1b31..444b5d4 100644 --- a/net/base/x509_certificate_openssl.cc +++ b/net/base/x509_certificate_openssl.cc @@ -128,20 +128,26 @@ void ParseDate(ASN1_TIME* x509_time, base::Time* time) { return; base::Time::Exploded exploded = {0}; - bool valid = base::StringToInt(str_date.substr(0, year_length), + bool valid = base::StringToInt(str_date.begin(), + str_date.begin() + year_length, &exploded.year); if (valid && year_length == 2) exploded.year += exploded.year < 50 ? 2000 : 1900; - valid &= base::StringToInt(str_date.substr(2 + fields_offset, 2), + valid &= base::StringToInt(str_date.begin() + fields_offset + 2, + str_date.begin() + fields_offset + 4, &exploded.month); - valid &= base::StringToInt(str_date.substr(4 + fields_offset, 2), + valid &= base::StringToInt(str_date.begin() + fields_offset + 4, + str_date.begin() + fields_offset + 6), &exploded.day_of_month); - valid &= base::StringToInt(str_date.substr(6 + fields_offset, 2), + valid &= base::StringToInt(str_date.begin() + fields_offset + 6, + str_date.begin() + fields_offset + 8), &exploded.hour); - valid &= base::StringToInt(str_date.substr(8 + fields_offset, 2), + valid &= base::StringToInt(str_date.begin() + fields_offset + 8, + str_date.begin() + fields_offset + 10), &exploded.minute); - valid &= base::StringToInt(str_date.substr(10 + fields_offset, 2), + valid &= base::StringToInt(str_date.begin() + fields_offset + 10, + str_date.begin() + fields_offset + 12, &exploded.second); DCHECK(valid); diff --git a/net/ftp/ftp_ctrl_response_buffer.cc b/net/ftp/ftp_ctrl_response_buffer.cc index 950e1e0..4aeef1f 100644 --- a/net/ftp/ftp_ctrl_response_buffer.cc +++ b/net/ftp/ftp_ctrl_response_buffer.cc @@ -91,7 +91,7 @@ FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( ParsedLine result; if (line.length() >= 3) { - if (base::StringToInt(line.substr(0, 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_directory_listing_parser_mlsd.cc b/net/ftp/ftp_directory_listing_parser_mlsd.cc index fa9a44e..d8ae618 100644 --- a/net/ftp/ftp_directory_listing_parser_mlsd.cc +++ b/net/ftp/ftp_directory_listing_parser_mlsd.cc @@ -28,15 +28,23 @@ bool MlsdDateListingToTime(const string16& text, base::Time* time) { if (text.length() < 14) return false; - if (!base::StringToInt(text.substr(0, 4), &time_exploded.year)) + if (!base::StringToInt(text.begin(), text.begin() + 4, &time_exploded.year)) return false; - if (!base::StringToInt(text.substr(4, 2), &time_exploded.month)) + if (!base::StringToInt(text.begin() + 4, + text.begin() + 6, + &time_exploded.month)) return false; - if (!base::StringToInt(text.substr(6, 2), &time_exploded.day_of_month)) + if (!base::StringToInt(text.begin() + 6, + text.begin() + 8, + &time_exploded.day_of_month)) return false; - if (!base::StringToInt(text.substr(8, 2), &time_exploded.hour)) + if (!base::StringToInt(text.begin() + 8, + text.begin() + 10, + &time_exploded.hour)) return false; - if (!base::StringToInt(text.substr(10, 2), &time_exploded.minute)) + if (!base::StringToInt(text.begin() + 10, + text.begin() + 12, + &time_exploded.minute)) return false; // We don't know the time zone of the server, so just use local time. diff --git a/net/ftp/ftp_util.cc b/net/ftp/ftp_util.cc index aeb2355..2633e9d 100644 --- a/net/ftp/ftp_util.cc +++ b/net/ftp/ftp_util.cc @@ -162,17 +162,25 @@ 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(rest.substr(0, 2), &time_exploded.hour)) + if (!base::StringToInt(rest.begin(), + rest.begin() + 2, + &time_exploded.hour)) return false; - if (!base::StringToInt(rest.substr(3, 2), &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(rest.substr(0, 1), &time_exploded.hour)) + if (!base::StringToInt(rest.begin(), + rest.begin() + 1, + &time_exploded.hour)) return false; - if (!base::StringToInt(rest.substr(2, 2), &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 455c9ed..d5b16dd 100644 --- a/net/http/http_chunked_decoder.cc +++ b/net/http/http_chunked_decoder.cc @@ -192,7 +192,7 @@ bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { return false; int parsed_number; - bool ok = base::HexStringToInt(std::string(start, len), &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 99c5404..7376fa0 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -598,7 +598,7 @@ void HttpResponseHeaders::ParseStatusLine( raw_headers_.push_back(' '); raw_headers_.append(code, p); raw_headers_.push_back(' '); - base::StringToInt(std::string(code, p), &response_code_); + base::StringToInt(code, p, &response_code_); // Skip whitespace. while (*p == ' ') @@ -973,7 +973,9 @@ bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { value.begin() + kMaxAgePrefixLen, kMaxAgePrefix)) { int64 seconds; - base::StringToInt64(value.substr(kMaxAgePrefixLen), &seconds); + base::StringToInt64(value.begin() + kMaxAgePrefixLen, + value.end(), + &seconds); *result = TimeDelta::FromSeconds(seconds); return true; } @@ -1148,9 +1150,9 @@ 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( - std::string(first_byte_pos_begin, first_byte_pos_end), - first_byte_position); + bool ok = base::StringToInt64(first_byte_pos_begin, + first_byte_pos_end, + first_byte_position); // Obtain last-byte-pos. std::string::const_iterator last_byte_pos_begin = @@ -1159,9 +1161,9 @@ 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( - std::string(last_byte_pos_begin, last_byte_pos_end), - last_byte_position); + ok &= base::StringToInt64(last_byte_pos_begin, + last_byte_pos_end, + last_byte_position); if (!ok) { *first_byte_position = *last_byte_position = -1; return false; @@ -1184,9 +1186,9 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position, if (LowerCaseEqualsASCII(instance_length_begin, instance_length_end, "*")) { return false; - } else if (!base::StringToInt64( - std::string(instance_length_begin, instance_length_end), - instance_length)) { + } 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 757d817..67b147a 100644 --- a/net/proxy/proxy_bypass_rules.cc +++ b/net/proxy/proxy_bypass_rules.cc @@ -264,7 +264,7 @@ bool ProxyBypassRules::AddRuleFromStringInternal( host = raw; port = -1; if (pos_colon != std::string::npos) { - if (!base::StringToInt(raw.substr(pos_colon + 1), &port) || + if (!base::StringToInt(raw.begin() + pos_colon + 1, raw.end(), &port) || (port < 0 || port > 0xFFFF)) { return false; // Port was invalid. } diff --git a/webkit/glue/multipart_response_delegate.cc b/webkit/glue/multipart_response_delegate.cc index 4839a91..99a9e4c 100644 --- a/webkit/glue/multipart_response_delegate.cc +++ b/webkit/glue/multipart_response_delegate.cc @@ -342,12 +342,6 @@ bool MultipartResponseDelegate::ReadContentRanges( return false; } - size_t byte_range_lower_bound_characters = - byte_range_lower_bound_end_offset - byte_range_lower_bound_start_offset; - std::string byte_range_lower_bound = - content_range.substr(byte_range_lower_bound_start_offset, - byte_range_lower_bound_characters); - size_t byte_range_upper_bound_start_offset = byte_range_lower_bound_end_offset + 1; @@ -357,16 +351,16 @@ bool MultipartResponseDelegate::ReadContentRanges( return false; } - size_t byte_range_upper_bound_characters = - byte_range_upper_bound_end_offset - byte_range_upper_bound_start_offset; - - std::string byte_range_upper_bound = - content_range.substr(byte_range_upper_bound_start_offset, - byte_range_upper_bound_characters); - - if (!base::StringToInt(byte_range_lower_bound, content_range_lower_bound)) + if (!base::StringToInt( + content_range.begin() + byte_range_lower_bound_start_offset, + content_range.begin() + byte_range_lower_bound_end_offset, + content_range_lower_bound)) return false; - if (!base::StringToInt(byte_range_upper_bound, content_range_upper_bound)) + + if (!base::StringToInt( + content_range.begin() + byte_range_upper_bound_start_offset, + content_range.begin() + byte_range_upper_bound_end_offset, + content_range_upper_bound)) return false; return true; } diff --git a/webkit/tools/test_shell/listener_leak_test.cc b/webkit/tools/test_shell/listener_leak_test.cc index 6f2fc4d..ce8fe3f 100644 --- a/webkit/tools/test_shell/listener_leak_test.cc +++ b/webkit/tools/test_shell/listener_leak_test.cc @@ -44,7 +44,9 @@ static int GetNumObjects(int log_skip, const std::string& constructor) { size_t j = v8_log.find(",", i); CHECK(j != std::string::npos); int num_objects; - CHECK(base::StringToInt(v8_log.substr(i, j - i), &num_objects)); + CHECK(base::StringToInt(v8_log.begin() + i, + v8_log.begin() + j, + &num_objects)); return num_objects; } |