diff options
Diffstat (limited to 'components')
42 files changed, 231 insertions, 234 deletions
diff --git a/components/autofill/content/browser/risk/fingerprint.cc b/components/autofill/content/browser/risk/fingerprint.cc index b4ea952..dfee9b5 100644 --- a/components/autofill/content/browser/risk/fingerprint.cc +++ b/components/autofill/content/browser/risk/fingerprint.cc @@ -113,12 +113,10 @@ void AddPluginsToFingerprint(const std::vector<content::WebPluginInfo>& plugins, void AddAcceptLanguagesToFingerprint( const std::string& accept_languages_str, Fingerprint::MachineCharacteristics* machine) { - std::vector<std::string> accept_languages; - base::SplitString(accept_languages_str, ',', &accept_languages); - for (std::vector<std::string>::const_iterator it = accept_languages.begin(); - it != accept_languages.end(); ++it) { - machine->add_requested_language(*it); - } + for (const std::string& lang : + base::SplitString(accept_languages_str, ",", base::TRIM_WHITESPACE, + base::SPLIT_WANT_ALL)) + machine->add_requested_language(lang); } // This function writes diff --git a/components/autofill/content/browser/wallet/wallet_address.cc b/components/autofill/content/browser/wallet/wallet_address.cc index 0e11196..aa9beb8 100644 --- a/components/autofill/content/browser/wallet/wallet_address.cc +++ b/components/autofill/content/browser/wallet/wallet_address.cc @@ -132,8 +132,9 @@ Address::Address(const AutofillProfile& profile) phone_number_(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)), is_complete_address_(true), language_code_(profile.language_code()) { - base::SplitString( - profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS), '\n', &street_address_); + street_address_ = base::SplitString( + profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS), base::ASCIIToUTF16("\n"), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (!country_name_code_.empty()) phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_); diff --git a/components/autofill/content/renderer/autofill_agent.cc b/components/autofill/content/renderer/autofill_agent.cc index ef46edb..e78316e 100644 --- a/components/autofill/content/renderer/autofill_agent.cc +++ b/components/autofill/content/renderer/autofill_agent.cc @@ -90,7 +90,7 @@ void GetDataListSuggestions(const WebInputElement& element, if (element.isMultiple() && element.isEmailField()) { const base::char16 comma[2] = { ',', 0 }; std::vector<base::string16> parts = base::SplitString( - prefix, comma, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); + prefix, comma, base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (parts.size() > 0) { base::TrimWhitespace(parts[parts.size() - 1], base::TRIM_LEADING, &prefix); @@ -485,10 +485,9 @@ void AutofillAgent::AcceptDataListSuggestion( // If this element takes multiple values then replace the last part with // the suggestion. if (input_element->isMultiple() && input_element->isEmailField()) { - std::vector<base::string16> parts; - - base::SplitStringDontTrim( - base::StringPiece16(input_element->editingValue()), ',', &parts); + std::vector<base::string16> parts = base::SplitString( + base::StringPiece16(input_element->editingValue()), + base::ASCIIToUTF16(","), base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); if (parts.size() == 0) parts.push_back(base::string16()); diff --git a/components/autofill/core/browser/address.cc b/components/autofill/core/browser/address.cc index 389bed2..2cf5f51 100644 --- a/components/autofill/core/browser/address.cc +++ b/components/autofill/core/browser/address.cc @@ -130,7 +130,9 @@ void Address::SetRawInfo(ServerFieldType type, const base::string16& value) { break; case ADDRESS_HOME_STREET_ADDRESS: - base::SplitString(value, base::char16('\n'), &street_address_); + street_address_ = base::SplitString( + value, base::ASCIIToUTF16("\n"), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); break; default: diff --git a/components/autofill/core/browser/address_i18n.cc b/components/autofill/core/browser/address_i18n.cc index 24af61a..ca74fc5 100644 --- a/components/autofill/core/browser/address_i18n.cc +++ b/components/autofill/core/browser/address_i18n.cc @@ -48,11 +48,10 @@ scoped_ptr<AddressData> CreateAddressData( get_info.Run(AutofillType(ADDRESS_HOME_SORTING_CODE))); address_data->postal_code = base::UTF16ToUTF8( get_info.Run(AutofillType(ADDRESS_HOME_ZIP))); - base::SplitString( + address_data->address_line = base::SplitString( base::UTF16ToUTF8( get_info.Run(AutofillType(ADDRESS_HOME_STREET_ADDRESS))), - '\n', - &address_data->address_line); + "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); return address_data.Pass(); } diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc index 33e5b6e..d7833b1 100644 --- a/components/autofill/core/browser/autofill_field.cc +++ b/components/autofill/core/browser/autofill_field.cc @@ -102,7 +102,9 @@ bool SetSelectControlValueTokenMatch(const base::string16& value, l10n::CaseInsensitiveCompare compare; for (size_t i = 0; i < field->option_values.size(); ++i) { - base::SplitStringAlongWhitespace(field->option_values[i], &tokenized); + tokenized = base::SplitString( + field->option_values[i], base::kWhitespaceASCIIAs16, + base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); if (std::find_if(tokenized.begin(), tokenized.end(), [&compare, value](base::string16& rhs) { return compare.StringsEqual(value, rhs); @@ -111,7 +113,9 @@ bool SetSelectControlValueTokenMatch(const base::string16& value, return true; } - base::SplitStringAlongWhitespace(field->option_contents[i], &tokenized); + tokenized = base::SplitString( + field->option_contents[i], base::kWhitespaceASCIIAs16, + base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); if (std::find_if(tokenized.begin(), tokenized.end(), [&compare, value](base::string16& rhs) { return compare.StringsEqual(value, rhs); @@ -333,8 +337,9 @@ bool FillSelectControl(const AutofillType& type, // formatted as MM/YYYY. If it isn't, filling will fail. bool FillMonthControl(const base::string16& value, FormFieldData* field) { // Autofill formats a combined date as month/year. - std::vector<base::string16> pieces; - base::SplitString(value, base::char16('/'), &pieces); + std::vector<base::string16> pieces = base::SplitString( + value, base::ASCIIToUTF16("/"), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (pieces.size() != 2) return false; @@ -365,7 +370,9 @@ void FillStreetAddress(const base::string16& value, AddressData address_data; address_data.language_code = address_language_code; - base::SplitString(base::UTF16ToUTF8(value), '\n', &address_data.address_line); + address_data.address_line = base::SplitString( + base::UTF16ToUTF8(value), "\n", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); std::string line; GetStreetAddressLinesAsSingleLine(address_data, &line); field->value = base::UTF8ToUTF16(line); diff --git a/components/autofill/core/browser/credit_card.cc b/components/autofill/core/browser/credit_card.cc index b4c1c9e..6f26a14 100644 --- a/components/autofill/core/browser/credit_card.cc +++ b/components/autofill/core/browser/credit_card.cc @@ -448,9 +448,10 @@ void CreditCard::SetInfoForMonthInputType(const base::string16& value) { return; } - std::vector<base::string16> year_month; - base::SplitString(value, L'-', &year_month); - DCHECK_EQ((int)year_month.size(), 2); + std::vector<base::StringPiece16> year_month = base::SplitStringPiece( + value, base::ASCIIToUTF16("-"), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + DCHECK_EQ(2u, year_month.size()); int num = 0; bool converted = false; converted = base::StringToInt(year_month[0], &num); diff --git a/components/bookmarks/browser/bookmark_index_unittest.cc b/components/bookmarks/browser/bookmark_index_unittest.cc index cab18e5..c7e8f53 100644 --- a/components/bookmarks/browser/bookmark_index_unittest.cc +++ b/components/bookmarks/browser/bookmark_index_unittest.cc @@ -109,11 +109,11 @@ class BookmarkIndexTest : public testing::Test { void ExtractMatchPositions(const std::string& string, BookmarkMatch::MatchPositions* matches) { - std::vector<std::string> match_strings; - base::SplitString(string, ':', &match_strings); - for (size_t i = 0; i < match_strings.size(); ++i) { - std::vector<std::string> chunks; - base::SplitString(match_strings[i], ',', &chunks); + for (const base::StringPiece& match : + base::SplitStringPiece(string, ":", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + std::vector<base::StringPiece> chunks = base::SplitStringPiece( + match, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); ASSERT_EQ(2U, chunks.size()); matches->push_back(BookmarkMatch::MatchPosition()); int chunks0, chunks1; @@ -192,18 +192,20 @@ TEST_F(BookmarkIndexTest, GetBookmarksMatching) { { "abc def", "abc d", "" }, }; for (size_t i = 0; i < arraysize(data); ++i) { - std::vector<std::string> titles; - base::SplitString(data[i].titles, ';', &titles); std::vector<TitleAndURL> bookmarks; - for (size_t j = 0; j < titles.size(); ++j) { - TitleAndURL bookmark(titles[j], kAboutBlankURL); + for (const std::string& title : base::SplitString( + data[i].titles, ";", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + TitleAndURL bookmark(title, kAboutBlankURL); bookmarks.push_back(bookmark); } AddBookmarks(bookmarks); std::vector<std::string> expected; - if (!data[i].expected.empty()) - base::SplitString(data[i].expected, ';', &expected); + if (!data[i].expected.empty()) { + expected = base::SplitString(data[i].expected, ";", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + } ExpectMatches(data[i].query, query_parser::MatchingAlgorithm::DEFAULT, expected); @@ -251,18 +253,20 @@ TEST_F(BookmarkIndexTest, GetBookmarksMatchingAlwaysPrefixSearch) { { "ab cdef;abcd;abcd cdefg", "ab cdef", "ab cdef;abcd cdefg" }, }; for (size_t i = 0; i < arraysize(data); ++i) { - std::vector<std::string> titles; - base::SplitString(data[i].titles, ';', &titles); std::vector<TitleAndURL> bookmarks; - for (size_t j = 0; j < titles.size(); ++j) { - TitleAndURL bookmark(titles[j], kAboutBlankURL); + for (const std::string& title : base::SplitString( + data[i].titles, ";", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + TitleAndURL bookmark(title, kAboutBlankURL); bookmarks.push_back(bookmark); } AddBookmarks(bookmarks); std::vector<std::string> expected; - if (!data[i].expected.empty()) - base::SplitString(data[i].expected, ';', &expected); + if (!data[i].expected.empty()) { + expected = base::SplitString(data[i].expected, ";", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + } ExpectMatches(data[i].query, query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH, diff --git a/components/bookmarks/browser/bookmark_model_unittest.cc b/components/bookmarks/browser/bookmark_model_unittest.cc index 271d182..ac22fbf 100644 --- a/components/bookmarks/browser/bookmark_model_unittest.cc +++ b/components/bookmarks/browser/bookmark_model_unittest.cc @@ -160,8 +160,9 @@ void PopulateNodeImpl(const std::vector<std::string>& description, // NOTE: each name must be unique, and folders are assigned a unique title by // way of an increasing integer. void PopulateNodeFromString(const std::string& description, TestNode* parent) { - std::vector<std::string> elements; - base::SplitStringAlongWhitespace(description, &elements); + std::vector<std::string> elements = base::SplitString( + description, base::kWhitespaceASCII, + base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); size_t index = 0; PopulateNodeImpl(elements, &index, parent); } diff --git a/components/content_settings/core/browser/content_settings_utils.cc b/components/content_settings/core/browser/content_settings_utils.cc index eb91f0b..5c48e9b 100644 --- a/components/content_settings/core/browser/content_settings_utils.cc +++ b/components/content_settings/core/browser/content_settings_utils.cc @@ -112,8 +112,9 @@ std::string CreatePatternString( } PatternPair ParsePatternString(const std::string& pattern_str) { - std::vector<std::string> pattern_str_list; - base::SplitString(pattern_str, kPatternSeparator[0], &pattern_str_list); + std::vector<std::string> pattern_str_list = base::SplitString( + pattern_str, std::string(1, kPatternSeparator[0]), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); // If the |pattern_str| is an empty string then the |pattern_string_list| // contains a single empty string. In this case the empty string will be diff --git a/components/content_settings/core/common/content_settings_pattern.cc b/components/content_settings/core/common/content_settings_pattern.cc index b02cbee..634e487 100644 --- a/components/content_settings/core/common/content_settings_pattern.cc +++ b/components/content_settings/core/common/content_settings_pattern.cc @@ -47,17 +47,16 @@ bool IsSubDomainOrEqual(const std::string& sub_domain, // Compares two domain names. int CompareDomainNames(const std::string& str1, const std::string& str2) { - std::vector<std::string> domain_name1; - std::vector<std::string> domain_name2; - - base::SplitString(str1, '.', &domain_name1); - base::SplitString(str2, '.', &domain_name2); + std::vector<base::StringPiece> domain_name1 = base::SplitStringPiece( + str1, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + std::vector<base::StringPiece> domain_name2 = base::SplitStringPiece( + str2, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); int i1 = static_cast<int>(domain_name1.size()) - 1; int i2 = static_cast<int>(domain_name2.size()) - 1; int rv; while (i1 >= 0 && i2 >= 0) { - // domain names are stored in puny code. So it's fine to use the compare + // Domain names are stored in puny code. So it's fine to use the compare // method. rv = domain_name1[i1].compare(domain_name2[i2]); if (rv != 0) diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc index eff059e..24be61b 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc @@ -87,11 +87,11 @@ bool DataReductionProxyRequestOptions::ParseLocalSessionKey( const std::string& session_key, std::string* session, std::string* credentials) { - std::vector<std::string> auth_values; - base::SplitString(session_key, '|', &auth_values); + std::vector<base::StringPiece> auth_values = base::SplitStringPiece( + session_key, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (auth_values.size() == 2) { - *session = auth_values[0]; - *credentials = auth_values[1]; + auth_values[0].CopyToString(session); + auth_values[1].CopyToString(credentials); return true; } @@ -145,12 +145,12 @@ void DataReductionProxyRequestOptions::GetChromiumBuildAndPatch( const std::string& version, std::string* build, std::string* patch) const { - std::vector<std::string> version_parts; - base::SplitString(version, '.', &version_parts); + std::vector<base::StringPiece> version_parts = base::SplitStringPiece( + version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (version_parts.size() != 4) return; - *build = version_parts[2]; - *patch = version_parts[3]; + version_parts[2].CopyToString(build); + version_parts[3].CopyToString(patch); } void DataReductionProxyRequestOptions::UpdateVersion() { diff --git a/components/device_event_log/device_event_log_impl_unittest.cc b/components/device_event_log/device_event_log_impl_unittest.cc index 706039d..0154bd4 100644 --- a/components/device_event_log/device_event_log_impl_unittest.cc +++ b/components/device_event_log/device_event_log_impl_unittest.cc @@ -53,14 +53,13 @@ class DeviceEventLogTest : public testing::Test { protected: std::string SkipTime(const std::string& input) { std::string output; - std::vector<std::string> lines; - base::SplitString(input, '\n', &lines); - for (size_t i = 0; i < lines.size(); ++i) { - size_t n = lines[i].find(']'); + for (const std::string& line : base::SplitString( + input, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + size_t n = line.find(']'); if (n != std::string::npos) - output += "[time] " + lines[i].substr(n + 2) + '\n'; + output += "[time] " + line.substr(n + 2) + '\n'; else - output += lines[i]; + output += line; } return output; } diff --git a/components/dom_distiller/standalone/content_extractor_browsertest.cc b/components/dom_distiller/standalone/content_extractor_browsertest.cc index 963d181..de20ade 100644 --- a/components/dom_distiller/standalone/content_extractor_browsertest.cc +++ b/components/dom_distiller/standalone/content_extractor_browsertest.cc @@ -248,8 +248,8 @@ class ContentExtractionRequest : public ViewRequestDelegate { } } else if (command_line.HasSwitch(kUrlsSwitch)) { std::string urls_string = command_line.GetSwitchValueASCII(kUrlsSwitch); - std::vector<std::string> urls; - base::SplitString(urls_string, ' ', &urls); + std::vector<std::string> urls = base::SplitString( + urls_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); // Check for original-urls switch, which must exactly pair up with // |kUrlsSwitch| i.e. number of original urls must be same as that of // urls. @@ -257,8 +257,11 @@ class ContentExtractionRequest : public ViewRequestDelegate { if (command_line.HasSwitch(kOriginalUrls)) { std::string original_urls_string = command_line.GetSwitchValueASCII(kOriginalUrls); - base::SplitString(original_urls_string, ' ', &original_urls); - if (original_urls.size() != urls.size()) original_urls.clear(); + original_urls = base::SplitString( + original_urls_string, " ", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + if (original_urls.size() != urls.size()) + original_urls.clear(); } for (size_t i = 0; i < urls.size(); ++i) { GURL url(urls[i]); diff --git a/components/favicon_base/fallback_icon_url_parser.cc b/components/favicon_base/fallback_icon_url_parser.cc index ba9f2321..8855695b 100644 --- a/components/favicon_base/fallback_icon_url_parser.cc +++ b/components/favicon_base/fallback_icon_url_parser.cc @@ -74,8 +74,8 @@ bool ParsedFallbackIconPath::ParseSpecs( DCHECK(size); DCHECK(style); - std::vector<std::string> tokens; - base::SplitStringDontTrim(specs_str, ',', &tokens); + std::vector<std::string> tokens = base::SplitString( + specs_str, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); if (tokens.size() != 5) // Force "," for empty fields. return false; diff --git a/components/history/core/browser/top_sites_database.cc b/components/history/core/browser/top_sites_database.cc index d1f024d..00c4559 100644 --- a/components/history/core/browser/top_sites_database.cc +++ b/components/history/core/browser/top_sites_database.cc @@ -90,12 +90,12 @@ std::string GetRedirects(const MostVisitedURL& url) { // Decodes redirects from a string and sets them for the url. void SetRedirects(const std::string& redirects, MostVisitedURL* url) { - std::vector<std::string> redirects_vector; - base::SplitStringAlongWhitespace(redirects, &redirects_vector); - for (size_t i = 0; i < redirects_vector.size(); ++i) { - GURL redirects_url(redirects_vector[i]); - if (redirects_url.is_valid()) - url->redirects.push_back(redirects_url); + for (const std::string& redirect : base::SplitString( + redirects, base::kWhitespaceASCII, + base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { + GURL redirect_url(redirect); + if (redirect_url.is_valid()) + url->redirects.push_back(redirect_url); } } diff --git a/components/metrics/net/network_metrics_provider.cc b/components/metrics/net/network_metrics_provider.cc index 12054a9..aa4acc2 100644 --- a/components/metrics/net/network_metrics_provider.cc +++ b/components/metrics/net/network_metrics_provider.cc @@ -226,13 +226,10 @@ void NetworkMetricsProvider::WriteWifiAccessPointProto( return; // Parse OUI list. - std::vector<std::string> oui_list; - base::SplitString(info.oui_list, ' ', &oui_list); - for (std::vector<std::string>::const_iterator it = oui_list.begin(); - it != oui_list.end(); - ++it) { + for (const base::StringPiece& oui_str : base::SplitStringPiece( + info.oui_list, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { uint32 oui; - if (base::HexStringToUInt(*it, &oui)) + if (base::HexStringToUInt(oui_str, &oui)) vendor->add_element_identifier(oui); else NOTREACHED(); diff --git a/components/metrics/serialization/metric_sample.cc b/components/metrics/serialization/metric_sample.cc index 107fc3e..a012474 100644 --- a/components/metrics/serialization/metric_sample.cc +++ b/components/metrics/serialization/metric_sample.cc @@ -118,8 +118,8 @@ scoped_ptr<MetricSample> MetricSample::HistogramSample( // static scoped_ptr<MetricSample> MetricSample::ParseHistogram( const std::string& serialized_histogram) { - std::vector<std::string> parts; - base::SplitString(serialized_histogram, ' ', &parts); + std::vector<base::StringPiece> parts = base::SplitStringPiece( + serialized_histogram, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (parts.size() != 5) return scoped_ptr<MetricSample>(); @@ -131,7 +131,7 @@ scoped_ptr<MetricSample> MetricSample::ParseHistogram( return scoped_ptr<MetricSample>(); } - return HistogramSample(parts[0], sample, min, max, bucket_count); + return HistogramSample(parts[0].as_string(), sample, min, max, bucket_count); } // static @@ -145,15 +145,15 @@ scoped_ptr<MetricSample> MetricSample::SparseHistogramSample( // static scoped_ptr<MetricSample> MetricSample::ParseSparseHistogram( const std::string& serialized_histogram) { - std::vector<std::string> parts; - base::SplitString(serialized_histogram, ' ', &parts); + std::vector<base::StringPiece> parts = base::SplitStringPiece( + serialized_histogram, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (parts.size() != 2) return scoped_ptr<MetricSample>(); int sample; if (parts[0].empty() || !base::StringToInt(parts[1], &sample)) return scoped_ptr<MetricSample>(); - return SparseHistogramSample(parts[0], sample); + return SparseHistogramSample(parts[0].as_string(), sample); } // static @@ -168,9 +168,9 @@ scoped_ptr<MetricSample> MetricSample::LinearHistogramSample( // static scoped_ptr<MetricSample> MetricSample::ParseLinearHistogram( const std::string& serialized_histogram) { - std::vector<std::string> parts; + std::vector<base::StringPiece> parts = base::SplitStringPiece( + serialized_histogram, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); int sample, max; - base::SplitString(serialized_histogram, ' ', &parts); if (parts.size() != 3) return scoped_ptr<MetricSample>(); if (parts[0].empty() || !base::StringToInt(parts[1], &sample) || @@ -178,7 +178,7 @@ scoped_ptr<MetricSample> MetricSample::ParseLinearHistogram( return scoped_ptr<MetricSample>(); } - return LinearHistogramSample(parts[0], sample, max); + return LinearHistogramSample(parts[0].as_string(), sample, max); } // static diff --git a/components/metrics/serialization/serialization_utils.cc b/components/metrics/serialization/serialization_utils.cc index 5dc71a4..6d6aa0b 100644 --- a/components/metrics/serialization/serialization_utils.cc +++ b/components/metrics/serialization/serialization_utils.cc @@ -91,8 +91,9 @@ scoped_ptr<MetricSample> SerializationUtils::ParseSample( if (sample.empty()) return scoped_ptr<MetricSample>(); - std::vector<std::string> parts; - base::SplitString(sample, '\0', &parts); + std::vector<std::string> parts = base::SplitString( + sample, std::string(1, '\0'), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); // We should have two null terminated strings so split should produce // three chunks. if (parts.size() != 3) { diff --git a/components/nacl/browser/nacl_process_host.cc b/components/nacl/browser/nacl_process_host.cc index cc292bf..3e7f923 100644 --- a/components/nacl/browser/nacl_process_host.cc +++ b/components/nacl/browser/nacl_process_host.cc @@ -109,12 +109,9 @@ void FindAddressSpace(base::ProcessHandle process, #ifdef _DLL bool IsInPath(const std::string& path_env_var, const std::string& dir) { - std::vector<std::string> split; - base::SplitString(path_env_var, ';', &split); - for (std::vector<std::string>::const_iterator i(split.begin()); - i != split.end(); - ++i) { - if (*i == dir) + for (const base::StringPiece& cur : base::SplitStringPiece( + path_env_var, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + if (cur == dir) return true; } return false; @@ -558,11 +555,10 @@ void NaClProcessHost::LaunchNaClGdb() { #else base::CommandLine::StringType nacl_gdb = command_line.GetSwitchValueNative(switches::kNaClGdb); - base::CommandLine::StringVector argv; // We don't support spaces inside arguments in --nacl-gdb switch. - base::SplitString(nacl_gdb, static_cast<base::CommandLine::CharType>(' '), - &argv); - base::CommandLine cmd_line(argv); + base::CommandLine cmd_line(base::SplitString( + nacl_gdb, base::CommandLine::StringType(1, ' '), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)); #endif cmd_line.AppendArg("--eval-command"); base::FilePath::StringType irt_path( diff --git a/components/nacl/renderer/ppb_nacl_private_impl.cc b/components/nacl/renderer/ppb_nacl_private_impl.cc index 3d67fc701..bc7854f 100644 --- a/components/nacl/renderer/ppb_nacl_private_impl.cc +++ b/components/nacl/renderer/ppb_nacl_private_impl.cc @@ -1557,12 +1557,9 @@ class PexeDownloader : public blink::WebURLLoaderClient { std::string cache_control = response.httpHeaderField("cache-control").utf8(); - std::vector<std::string> values; - base::SplitString(cache_control, ',', &values); - for (std::vector<std::string>::const_iterator it = values.begin(); - it != values.end(); - ++it) { - if (base::StringToLowerASCII(*it) == "no-store") + for (const std::string& cur : base::SplitString( + cache_control, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + if (base::StringToLowerASCII(cur) == "no-store") has_no_store_header = true; } diff --git a/components/nacl/zygote/nacl_fork_delegate_linux.cc b/components/nacl/zygote/nacl_fork_delegate_linux.cc index 12d265c..ae62564 100644 --- a/components/nacl/zygote/nacl_fork_delegate_linux.cc +++ b/components/nacl/zygote/nacl_fork_delegate_linux.cc @@ -447,8 +447,9 @@ void NaClForkDelegate::AddPassthroughEnvToOptions( std::string pass_through_string; std::vector<std::string> pass_through_vars; if (env->GetVar(kNaClEnvPassthrough, &pass_through_string)) { - base::SplitString( - pass_through_string, kNaClEnvPassthroughDelimiter, &pass_through_vars); + pass_through_vars = base::SplitString( + pass_through_string, std::string(1, kNaClEnvPassthroughDelimiter), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); } pass_through_vars.push_back(kNaClExeStderr); pass_through_vars.push_back(kNaClExeStdout); diff --git a/components/omnibox/browser/autocomplete_input.cc b/components/omnibox/browser/autocomplete_input.cc index d254b61..c8b744a 100644 --- a/components/omnibox/browser/autocomplete_input.cc +++ b/components/omnibox/browser/autocomplete_input.cc @@ -37,14 +37,14 @@ void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, void PopulateTermsPrefixedByHttpOrHttps( const base::string16& text, std::vector<base::string16>* terms_prefixed_by_http_or_https) { - std::vector<base::string16> terms; // Split on whitespace rather than use ICU's word iterator because, for // example, ICU's iterator may break on punctuation (such as ://) or decide // to split a single term in a hostname (if it seems to think that the // hostname is multiple words). Neither of these behaviors is desirable. - base::SplitString(text, ' ', &terms); const std::string separator(url::kStandardSchemeSeparator); - for (const auto& term : terms) { + for (const auto& term : + base::SplitString(text, base::ASCIIToUTF16(" "), + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { const std::string term_utf8(base::UTF16ToUTF8(term)); static const char* kSchemes[2] = { url::kHttpScheme, url::kHttpsScheme }; for (const char* scheme : kSchemes) { diff --git a/components/password_manager/core/browser/password_form_manager.cc b/components/password_manager/core/browser/password_form_manager.cc index f6738f8..a993ca6 100644 --- a/components/password_manager/core/browser/password_form_manager.cc +++ b/components/password_manager/core/browser/password_form_manager.cc @@ -110,8 +110,11 @@ PasswordFormManager::PasswordFormManager( submit_result_(kSubmitResultNotSubmitted), form_type_(kFormTypeUnspecified) { drivers_.push_back(driver); - if (observed_form_.origin.is_valid()) - base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); + if (observed_form_.origin.is_valid()) { + form_path_tokens_ = + base::SplitString(observed_form_.origin.path(), "/", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + } } PasswordFormManager::~PasswordFormManager() { @@ -938,8 +941,9 @@ int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { } else { // Walk the origin URL paths one directory at a time to see how // deep the two match. - std::vector<std::string> candidate_path_tokens; - base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); + std::vector<std::string> candidate_path_tokens = + base::SplitString(candidate.origin.path(), "/", base::TRIM_WHITESPACE, + base::SPLIT_WANT_ALL); size_t depth = 0; size_t max_dirs = std::min(form_path_tokens_.size(), candidate_path_tokens.size()); diff --git a/components/proximity_auth/bluetooth_util_chromeos.cc b/components/proximity_auth/bluetooth_util_chromeos.cc index 86a0758f..6a281fd 100644 --- a/components/proximity_auth/bluetooth_util_chromeos.cc +++ b/components/proximity_auth/bluetooth_util_chromeos.cc @@ -73,8 +73,8 @@ bool BluetoothAddressToBdaddr(const std::string& address, bdaddr_t* result) { if (canonical_address.empty()) return false; - std::vector<std::string> octets; - base::SplitString(canonical_address, ':', &octets); + std::vector<base::StringPiece> octets = base::SplitStringPiece( + canonical_address, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); DCHECK_EQ(octets.size(), 6U); // BlueZ expects the octets in the reverse order. diff --git a/components/query_parser/snippet.cc b/components/query_parser/snippet.cc index e393d60..2276e4a 100644 --- a/components/query_parser/snippet.cc +++ b/components/query_parser/snippet.cc @@ -167,8 +167,8 @@ void Snippet::ExtractMatchPositions(const std::string& offsets_str, DCHECK(match_positions); if (offsets_str.empty()) return; - std::vector<std::string> offsets; - base::SplitString(offsets_str, ' ', &offsets); + std::vector<std::string> offsets = base::SplitString( + offsets_str, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); // SQLite offsets are sets of four integers: // column, query term, match offset, match length // Matches within a string are marked by (start, end) pairs. diff --git a/components/query_parser/snippet_unittest.cc b/components/query_parser/snippet_unittest.cc index 7f96f67..c560d58 100644 --- a/components/query_parser/snippet_unittest.cc +++ b/components/query_parser/snippet_unittest.cc @@ -96,22 +96,18 @@ base::string16 BuildSnippet(const std::string& document, // |document|. We need to add more test cases and change this function // to be more generic depending on how we deal with 'folding for match' // in history. - const std::string document_folded = - base::StringToLowerASCII(std::string(document)); - - std::vector<std::string> query_words; - base::SplitString(query, ' ', &query_words); + const std::string document_folded = base::StringToLowerASCII(document); // Manually construct match_positions of the document. Snippet::MatchPositions match_positions; match_positions.clear(); - for (std::vector<std::string>::iterator qw = query_words.begin(); - qw != query_words.end(); ++qw) { + for (const std::string& word : base::SplitString( + query, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { // Insert all instances of this word into match_pairs. size_t ofs = 0; - while ((ofs = document_folded.find(*qw, ofs)) != std::string::npos) { - match_positions.push_back(std::make_pair(ofs, ofs + qw->size())); - ofs += qw->size(); + while ((ofs = document_folded.find(word, ofs)) != std::string::npos) { + match_positions.push_back(std::make_pair(ofs, ofs + word.size())); + ofs += word.size(); } } // Sort match_positions in order of increasing offset. diff --git a/components/search_engines/default_search_manager_unittest.cc b/components/search_engines/default_search_manager_unittest.cc index 02e15a6..6687ba3c 100644 --- a/components/search_engines/default_search_manager_unittest.cc +++ b/components/search_engines/default_search_manager_unittest.cc @@ -129,7 +129,8 @@ scoped_ptr<TemplateURLData> GenerateDummyTemplateURLData(std::string type) { data->favicon_url = GURL("http://icon1"); data->safe_for_autoreplace = true; data->show_in_default_list = true; - base::SplitString("UTF-8;UTF-16", ';', &data->input_encodings); + data->input_encodings = base::SplitString( + "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); data->date_created = base::Time(); data->last_modified = base::Time(); return data.Pass(); @@ -170,7 +171,8 @@ TEST_F(DefaultSearchManagerTest, ReadAndWritePref) { data.favicon_url = GURL("http://icon1"); data.safe_for_autoreplace = true; data.show_in_default_list = true; - base::SplitString("UTF-8;UTF-16", ';', &data.input_encodings); + data.input_encodings = base::SplitString( + "UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); data.date_created = base::Time(); data.last_modified = base::Time(); diff --git a/components/search_engines/default_search_pref_migration.cc b/components/search_engines/default_search_pref_migration.cc index c9f1b61..0abcd43 100644 --- a/components/search_engines/default_search_pref_migration.cc +++ b/components/search_engines/default_search_pref_migration.cc @@ -67,8 +67,9 @@ scoped_ptr<TemplateURLData> LoadDefaultSearchProviderFromLegacyPrefs( default_provider_data->show_in_default_list = true; default_provider_data->search_terms_replacement_key = prefs->GetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey); - base::SplitString(prefs->GetString(prefs::kDefaultSearchProviderEncodings), - ';', &default_provider_data->input_encodings); + default_provider_data->input_encodings = base::SplitString( + prefs->GetString(prefs::kDefaultSearchProviderEncodings), + ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); default_provider_data->alternate_urls.clear(); const base::ListValue* alternate_urls = diff --git a/components/search_engines/default_search_pref_test_util.cc b/components/search_engines/default_search_pref_test_util.cc index f09add3..22acd42 100644 --- a/components/search_engines/default_search_pref_test_util.cc +++ b/components/search_engines/default_search_pref_test_util.cc @@ -41,14 +41,10 @@ DefaultSearchPrefTestUtil::CreateDefaultSearchPreferenceValue( value->Set(DefaultSearchManager::kSearchTermsReplacementKey, new base::StringValue(search_terms_replacement_key)); - std::vector<std::string> encodings_items; - base::SplitString(encodings, ';', &encodings_items); scoped_ptr<base::ListValue> encodings_list(new base::ListValue); - for (std::vector<std::string>::const_iterator it = encodings_items.begin(); - it != encodings_items.end(); - ++it) { - encodings_list->AppendString(*it); - } + for (const std::string& term : base::SplitString( + encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) + encodings_list->AppendString(term); value->Set(DefaultSearchManager::kInputEncodings, encodings_list.release()); scoped_ptr<base::ListValue> alternate_url_list(new base::ListValue()); diff --git a/components/search_engines/keyword_table.cc b/components/search_engines/keyword_table.cc index 754c42e..2964102 100644 --- a/components/search_engines/keyword_table.cc +++ b/components/search_engines/keyword_table.cc @@ -313,7 +313,8 @@ bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, data->originating_url = GURL(s.ColumnString(6)); data->show_in_default_list = s.ColumnBool(10); data->safe_for_autoreplace = s.ColumnBool(5); - base::SplitString(s.ColumnString(9), ';', &data->input_encodings); + data->input_encodings = base::SplitString( + s.ColumnString(9), ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); data->id = s.ColumnInt64(0); data->date_created = Time::FromTimeT(s.ColumnInt64(7)); data->last_modified = Time::FromTimeT(s.ColumnInt64(15)); diff --git a/components/search_engines/template_url.cc b/components/search_engines/template_url.cc index 6ad91e9..3ca7188 100644 --- a/components/search_engines/template_url.cc +++ b/components/search_engines/template_url.cc @@ -711,15 +711,12 @@ std::string TemplateURLRef::ParseURL(const std::string& url, // Handles the post parameters. const std::string& post_params_string = GetPostParamsString(); if (!post_params_string.empty()) { - typedef std::vector<std::string> Strings; - Strings param_list; - base::SplitString(post_params_string, ',', ¶m_list); - - for (Strings::const_iterator iterator = param_list.begin(); - iterator != param_list.end(); ++iterator) { - Strings parts; + for (const base::StringPiece& cur : base::SplitStringPiece( + post_params_string, ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { // The '=' delimiter is required and the name must be not empty. - base::SplitString(*iterator, '=', &parts); + std::vector<std::string> parts = base::SplitString( + cur, "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if ((parts.size() != 2U) || parts[0].empty()) return std::string(); diff --git a/components/search_engines/template_url_service.cc b/components/search_engines/template_url_service.cc index fc889e8..a6b137b 100644 --- a/components/search_engines/template_url_service.cc +++ b/components/search_engines/template_url_service.cc @@ -1281,7 +1281,9 @@ TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( data.favicon_url = GURL(specifics.favicon_url()); data.show_in_default_list = specifics.show_in_default_list(); data.safe_for_autoreplace = specifics.safe_for_autoreplace(); - base::SplitString(specifics.input_encodings(), ';', &data.input_encodings); + data.input_encodings = base::SplitString( + specifics.input_encodings(), ";", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); // If the server data has duplicate encodings, we'll want to push an update // below to correct it. Note that we also fix this in // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct diff --git a/components/search_engines/template_url_service_unittest.cc b/components/search_engines/template_url_service_unittest.cc index 279ab18..e3c60c8 100644 --- a/components/search_engines/template_url_service_unittest.cc +++ b/components/search_engines/template_url_service_unittest.cc @@ -79,7 +79,8 @@ TemplateURL* CreateKeywordWithDate( data.favicon_url = GURL(favicon_url); data.safe_for_autoreplace = safe_for_autoreplace; data.show_in_default_list = show_in_default_list; - base::SplitString(encodings, ';', &data.input_encodings); + data.input_encodings = base::SplitString( + encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); data.date_created = date_created; data.last_modified = last_modified; return new TemplateURL(data); @@ -855,7 +856,8 @@ TEST_F(TemplateURLServiceTest, RepairSearchEnginesWithManagedDefault) { data.SetURL(kSearchURL); data.favicon_url = GURL(kIconURL); data.show_in_default_list = true; - base::SplitString(kEncodings, ';', &data.input_encodings); + data.input_encodings = base::SplitString( + kEncodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); data.alternate_urls.push_back(kAlternateURL); data.search_terms_replacement_key = kSearchTermsReplacementKey; scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); @@ -1234,7 +1236,8 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) { data.SetURL(kSearchURL); data.favicon_url = GURL(kIconURL); data.show_in_default_list = true; - base::SplitString(kEncodings, ';', &data.input_encodings); + data.input_encodings = base::SplitString( + kEncodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); data.alternate_urls.push_back(kAlternateURL); data.search_terms_replacement_key = kSearchTermsReplacementKey; scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL(data)); @@ -1477,7 +1480,8 @@ TEST_F(TemplateURLServiceTest, ExtensionEngineVsPolicy) { data.SetURL(kSearchURL); data.favicon_url = GURL(kIconURL); data.show_in_default_list = true; - base::SplitString(kEncodings, ';', &data.input_encodings); + data.input_encodings = base::SplitString( + kEncodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); data.alternate_urls.push_back(kAlternateURL); data.search_terms_replacement_key = kSearchTermsReplacementKey; scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data)); diff --git a/components/storage_monitor/media_transfer_protocol_device_observer_linux.cc b/components/storage_monitor/media_transfer_protocol_device_observer_linux.cc index e44fe091..7d093d9 100644 --- a/components/storage_monitor/media_transfer_protocol_device_observer_linux.cc +++ b/components/storage_monitor/media_transfer_protocol_device_observer_linux.cc @@ -36,9 +36,9 @@ std::string GetDeviceLocationFromStorageName(const std::string& storage_name) { // E.g. If the |storage_name| is "usb:2,2:65537", the storage identifier is // "65537". std::string GetStorageIdFromStorageName(const std::string& storage_name) { - std::vector<std::string> name_parts; - base::SplitString(storage_name, ':', &name_parts); - return name_parts.size() == 3 ? name_parts[2] : std::string(); + std::vector<base::StringPiece> name_parts = base::SplitStringPiece( + storage_name, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + return name_parts.size() == 3 ? name_parts[2].as_string() : std::string(); } // Returns a unique device id from the given |storage_info|. diff --git a/components/translate/core/browser/translate_accept_languages.cc b/components/translate/core/browser/translate_accept_languages.cc index 0a56713..57eea1c 100644 --- a/components/translate/core/browser/translate_accept_languages.cc +++ b/components/translate/core/browser/translate_accept_languages.cc @@ -62,22 +62,16 @@ void TranslateAcceptLanguages::InitAcceptLanguages(PrefService* prefs) { DCHECK(prefs); // Build the languages. accept_languages_.clear(); - std::string accept_langs_str = prefs->GetString( - accept_languages_pref_.c_str()); - std::vector<std::string> accept_langs_list; - base::SplitString(accept_langs_str, ',', &accept_langs_list); - std::vector<std::string>::const_iterator iter; - - for (iter = accept_langs_list.begin(); - iter != accept_langs_list.end(); ++iter) { + for (const base::StringPiece& lang : base::SplitStringPiece( + prefs->GetString(accept_languages_pref_), ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { // Get rid of the locale extension if any (ex: en-US -> en), but for Chinese // for which the CLD reports zh-CN and zh-TW. - std::string accept_lang(*iter); - size_t index = iter->find("-"); - if (index != std::string::npos && *iter != "zh-CN" && *iter != "zh-TW") - accept_lang = iter->substr(0, index); - - accept_languages_.insert(accept_lang); + size_t index = lang.find('-'); + if (index != base::StringPiece::npos && lang != "zh-CN" && lang != "zh-TW") + accept_languages_.insert(lang.substr(0, index).as_string()); + else + accept_languages_.insert(lang.as_string()); } } diff --git a/components/translate/core/browser/translate_manager.cc b/components/translate/core/browser/translate_manager.cc index 6b9abee..caafc03 100644 --- a/components/translate/core/browser/translate_manager.cc +++ b/components/translate/core/browser/translate_manager.cc @@ -144,9 +144,9 @@ void TranslateManager::InitiateTranslation(const std::string& page_lang) { } // Get the accepted languages list. - std::vector<std::string> accept_languages_list; - base::SplitString(prefs->GetString(accept_languages_pref_name_.c_str()), ',', - &accept_languages_list); + std::vector<std::string> accept_languages_list = base::SplitString( + prefs->GetString(accept_languages_pref_name_), ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); std::string target_lang = GetTargetLanguage(accept_languages_list); std::string language_code = diff --git a/components/translate/core/browser/translate_prefs.cc b/components/translate/core/browser/translate_prefs.cc index 571241a..0a7989de 100644 --- a/components/translate/core/browser/translate_prefs.cc +++ b/components/translate/core/browser/translate_prefs.cc @@ -79,8 +79,8 @@ void ExpandLanguageCodes(const std::vector<std::string>& languages, seen.insert(language); } - std::vector<std::string> tokens; - base::SplitString(language, '-', &tokens); + std::vector<std::string> tokens = base::SplitString( + language, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (tokens.size() == 0) continue; const std::string& main_part = tokens[0]; @@ -319,8 +319,8 @@ void TranslatePrefs::GetLanguageList(std::vector<std::string>* languages) { const char* key = accept_languages_pref_.c_str(); #endif - std::string languages_str = prefs_->GetString(key); - base::SplitString(languages_str, ',', languages); + *languages = base::SplitString(prefs_->GetString(key), ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); } void TranslatePrefs::UpdateLanguageList( @@ -449,10 +449,9 @@ void TranslatePrefs::MigrateUserPrefs(PrefService* user_prefs, std::vector<std::string> blacklisted_languages; GetBlacklistedLanguages(user_prefs, &blacklisted_languages); - std::string accept_languages_str = - user_prefs->GetString(accept_languages_pref); - std::vector<std::string> accept_languages; - base::SplitString(accept_languages_str, ',', &accept_languages); + std::vector<std::string> accept_languages = base::SplitString( + user_prefs->GetString(accept_languages_pref), ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); std::vector<std::string> blocked_languages; CreateBlockedLanguages( diff --git a/components/translate/core/common/translate_util.cc b/components/translate/core/common/translate_util.cc index 35c54a9..37d6a3e 100644 --- a/components/translate/core/common/translate_util.cc +++ b/components/translate/core/common/translate_util.cc @@ -21,12 +21,12 @@ void SplitIntoMainAndTail(const std::string& language, DCHECK(main_part); DCHECK(tail_part); - std::vector<std::string> chunks; - base::SplitString(language, '-', &chunks); - if (chunks.size() == 0u) + std::vector<base::StringPiece> chunks = base::SplitStringPiece( + language, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); + if (chunks.empty()) return; - *main_part = chunks[0]; + chunks[0].CopyToString(main_part); *tail_part = language.substr(main_part->size()); } diff --git a/components/translate/core/language_detection/language_detection_util.cc b/components/translate/core/language_detection/language_detection_util.cc index fe2befe..5c751a7 100644 --- a/components/translate/core/language_detection/language_detection_util.cc +++ b/components/translate/core/language_detection/language_detection_util.cc @@ -312,34 +312,32 @@ void CorrectLanguageCodeTypo(std::string* code) { bool IsValidLanguageCode(const std::string& code) { // Roughly check if the language code follows /[a-zA-Z]{2,3}(-[a-zA-Z]{2})?/. // TODO(hajimehoshi): How about es-419, which is used as an Accept language? - std::vector<std::string> chunks; - base::SplitString(code, '-', &chunks); + std::vector<base::StringPiece> chunks = base::SplitStringPiece( + code, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (chunks.size() < 1 || 2 < chunks.size()) return false; - const std::string& main_code = chunks[0]; + const base::StringPiece& main_code = chunks[0]; if (main_code.size() < 1 || 3 < main_code.size()) return false; - for (std::string::const_iterator it = main_code.begin(); - it != main_code.end(); ++it) { - if (!base::IsAsciiAlpha(*it)) + for (char c : main_code) { + if (!base::IsAsciiAlpha(c)) return false; } if (chunks.size() == 1) return true; - const std::string& sub_code = chunks[1]; + const base::StringPiece& sub_code = chunks[1]; if (sub_code.size() != 2) return false; - for (std::string::const_iterator it = sub_code.begin(); - it != sub_code.end(); ++it) { - if (!base::IsAsciiAlpha(*it)) + for (char c : sub_code) { + if (!base::IsAsciiAlpha(c)) return false; } @@ -348,17 +346,17 @@ bool IsValidLanguageCode(const std::string& code) { bool IsSameOrSimilarLanguages(const std::string& page_language, const std::string& cld_language) { - std::vector<std::string> chunks; - - base::SplitString(page_language, '-', &chunks); + std::vector<std::string> chunks = base::SplitString( + page_language, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (chunks.size() == 0) return false; - std::string page_language_main_part = chunks[0]; + std::string page_language_main_part = chunks[0]; // Need copy. - base::SplitString(cld_language, '-', &chunks); + chunks = base::SplitString( + cld_language, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); if (chunks.size() == 0) return false; - std::string cld_language_main_part = chunks[0]; + const std::string& cld_language_main_part = chunks[0]; // Language code part of |page_language| is matched to one of |cld_language|. // Country code is ignored here. diff --git a/components/variations/net/variations_http_header_provider.cc b/components/variations/net/variations_http_header_provider.cc index f94ad2c..ff8fd20 100644 --- a/components/variations/net/variations_http_header_provider.cc +++ b/components/variations/net/variations_http_header_provider.cc @@ -88,21 +88,20 @@ bool VariationsHttpHeaderProvider::SetDefaultVariationIds( const std::string& variation_ids) { default_variation_ids_set_.clear(); default_trigger_id_set_.clear(); - std::vector<std::string> entries; - base::SplitString(variation_ids, ',', &entries); - for (std::vector<std::string>::const_iterator it = entries.begin(); - it != entries.end(); ++it) { - if (it->empty()) { + for (const base::StringPiece& entry : base::SplitStringPiece( + variation_ids, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { + if (entry.empty()) { default_variation_ids_set_.clear(); default_trigger_id_set_.clear(); return false; } - bool trigger_id = base::StartsWith(*it, "t", base::CompareCase::SENSITIVE); + bool trigger_id = + base::StartsWith(entry, "t", base::CompareCase::SENSITIVE); // Remove the "t" prefix if it's there. - std::string entry = trigger_id ? it->substr(1) : *it; + base::StringPiece trimmed_entry = trigger_id ? entry.substr(1) : entry; int variation_id = 0; - if (!base::StringToInt(entry, &variation_id)) { + if (!base::StringToInt(trimmed_entry, &variation_id)) { default_variation_ids_set_.clear(); default_trigger_id_set_.clear(); return false; diff --git a/components/variations/study_filtering_unittest.cc b/components/variations/study_filtering_unittest.cc index d8f7f91..ae1a5f4 100644 --- a/components/variations/study_filtering_unittest.cc +++ b/components/variations/study_filtering_unittest.cc @@ -139,11 +139,11 @@ TEST(VariationsStudyFilteringTest, CheckStudyLocale) { }; for (size_t i = 0; i < arraysize(test_cases); ++i) { - std::vector<std::string> filter_locales; Study_Filter filter; - base::SplitString(test_cases[i].filter_locales, ',', &filter_locales); - for (size_t j = 0; j < filter_locales.size(); ++j) - filter.add_locale(filter_locales[j]); + for (const std::string& locale : base::SplitString( + test_cases[i].filter_locales, ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) + filter.add_locale(locale); EXPECT_EQ(test_cases[i].en_us_result, internal::CheckStudyLocale(filter, "en-US")); EXPECT_EQ(test_cases[i].en_ca_result, @@ -355,16 +355,15 @@ TEST(VariationsStudyFilteringTest, CheckStudyHardwareClass) { for (size_t i = 0; i < arraysize(test_cases); ++i) { Study_Filter filter; - std::vector<std::string> hardware_class; - base::SplitString(test_cases[i].hardware_class, ',', &hardware_class); - for (size_t j = 0; j < hardware_class.size(); ++j) - filter.add_hardware_class(hardware_class[j]); + for (const std::string& cur : base::SplitString( + test_cases[i].hardware_class, ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) + filter.add_hardware_class(cur); - std::vector<std::string> exclude_hardware_class; - base::SplitString(test_cases[i].exclude_hardware_class, ',', - &exclude_hardware_class); - for (size_t j = 0; j < exclude_hardware_class.size(); ++j) - filter.add_exclude_hardware_class(exclude_hardware_class[j]); + for (const std::string& cur : base::SplitString( + test_cases[i].exclude_hardware_class, ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) + filter.add_exclude_hardware_class(cur); EXPECT_EQ(test_cases[i].expected_result, internal::CheckStudyHardwareClass( @@ -406,14 +405,13 @@ TEST(VariationsStudyFilteringTest, CheckStudyCountry) { for (const auto& test : test_cases) { Study_Filter filter; - std::vector<std::string> countries; - base::SplitString(test.country, ',', &countries); - for (const std::string& country : countries) + for (const std::string& country : base::SplitString( + test.country, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) filter.add_country(country); - std::vector<std::string> exclude_countries; - base::SplitString(test.exclude_country, ',', &exclude_countries); - for (const std::string& exclude_country : exclude_countries) + for (const std::string& exclude_country : base::SplitString( + test.exclude_country, ",", + base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) filter.add_exclude_country(exclude_country); EXPECT_EQ(test.expected_result, |