Commit 8d858df9 authored by brettw's avatar brettw Committed by Commit bot

Make SplitStringUsingSubstr have consistent args.

The other split string functions have a consistent set of arguments that allow callers to specify whitespace handling and what to do with empty items. This one variant still used the old signature and passed through the parameters to the same backend.

This patch makes the parameters match the other forms and removes the legacy versions. There should be no behavior change since this should end up calling the same backend with the same parameters.

gesture_property_provider.cc changed to using a range-based for loop since it didn't need the temporary.

R=dcheng@chromium.org
TBR=bauerb@chromium.org (webui owners)

Review-Url: https://codereview.chromium.org/2356253006
Cr-Commit-Position: refs/heads/master@{#420562}
parent 9c3e6589
......@@ -227,18 +227,22 @@ bool SplitStringIntoKeyValuePairs(StringPiece input,
return success;
}
void SplitStringUsingSubstr(StringPiece16 input,
StringPiece16 delimiter,
std::vector<string16>* result) {
SplitStringUsingSubstrT(input, delimiter, TRIM_WHITESPACE, SPLIT_WANT_ALL,
result);
std::vector<string16> SplitStringUsingSubstr(StringPiece16 input,
StringPiece16 delimiter,
WhitespaceHandling whitespace,
SplitResult result_type) {
std::vector<string16> result;
SplitStringUsingSubstrT(input, delimiter, whitespace, result_type, &result);
return result;
}
void SplitStringUsingSubstr(StringPiece input,
StringPiece delimiter,
std::vector<std::string>* result) {
SplitStringUsingSubstrT(input, delimiter, TRIM_WHITESPACE, SPLIT_WANT_ALL,
result);
std::vector<std::string> SplitStringUsingSubstr(StringPiece input,
StringPiece delimiter,
WhitespaceHandling whitespace,
SplitResult result_type) {
std::vector<std::string> result;
SplitStringUsingSubstrT(input, delimiter, whitespace, result_type, &result);
return result;
}
std::vector<StringPiece16> SplitStringPieceUsingSubstr(
......
......@@ -90,16 +90,16 @@ BASE_EXPORT bool SplitStringIntoKeyValuePairs(StringPiece input,
// Similar to SplitString, but use a substring delimiter instead of a list of
// characters that are all possible delimiters.
//
// TODO(brettw) this should probably be changed and expanded to provide a
// mirror of the SplitString[Piece] API above, just with the different
// delimiter handling.
BASE_EXPORT void SplitStringUsingSubstr(StringPiece16 input,
StringPiece16 delimiter,
std::vector<string16>* result);
BASE_EXPORT void SplitStringUsingSubstr(StringPiece input,
StringPiece delimiter,
std::vector<std::string>* result);
BASE_EXPORT std::vector<string16> SplitStringUsingSubstr(
StringPiece16 input,
StringPiece16 delimiter,
WhitespaceHandling whitespace,
SplitResult result_type);
BASE_EXPORT std::vector<std::string> SplitStringUsingSubstr(
StringPiece input,
StringPiece delimiter,
WhitespaceHandling whitespace,
SplitResult result_type);
// Like SplitStringUsingSubstr above except it returns a vector of StringPieces
// which reference the original buffer without copying. Although you have to be
......
......@@ -150,8 +150,8 @@ TEST_F(SplitStringIntoKeyValuePairsTest, DelimiterInValue) {
}
TEST(SplitStringUsingSubstrTest, EmptyString) {
std::vector<std::string> results;
SplitStringUsingSubstr(std::string(), "DELIMITER", &results);
std::vector<std::string> results = SplitStringUsingSubstr(
std::string(), "DELIMITER", TRIM_WHITESPACE, SPLIT_WANT_ALL);
ASSERT_EQ(1u, results.size());
EXPECT_THAT(results, ElementsAre(""));
}
......@@ -231,38 +231,33 @@ TEST(StringUtilTest, SplitString_WhitespaceAndResultType) {
}
TEST(SplitStringUsingSubstrTest, StringWithNoDelimiter) {
std::vector<std::string> results;
SplitStringUsingSubstr("alongwordwithnodelimiter", "DELIMITER", &results);
std::vector<std::string> results = SplitStringUsingSubstr(
"alongwordwithnodelimiter", "DELIMITER", TRIM_WHITESPACE,
SPLIT_WANT_ALL);
ASSERT_EQ(1u, results.size());
EXPECT_THAT(results, ElementsAre("alongwordwithnodelimiter"));
}
TEST(SplitStringUsingSubstrTest, LeadingDelimitersSkipped) {
std::vector<std::string> results;
SplitStringUsingSubstr(
std::vector<std::string> results = SplitStringUsingSubstr(
"DELIMITERDELIMITERDELIMITERoneDELIMITERtwoDELIMITERthree",
"DELIMITER",
&results);
"DELIMITER", TRIM_WHITESPACE, SPLIT_WANT_ALL);
ASSERT_EQ(6u, results.size());
EXPECT_THAT(results, ElementsAre("", "", "", "one", "two", "three"));
}
TEST(SplitStringUsingSubstrTest, ConsecutiveDelimitersSkipped) {
std::vector<std::string> results;
SplitStringUsingSubstr(
std::vector<std::string> results = SplitStringUsingSubstr(
"unoDELIMITERDELIMITERDELIMITERdosDELIMITERtresDELIMITERDELIMITERcuatro",
"DELIMITER",
&results);
"DELIMITER", TRIM_WHITESPACE, SPLIT_WANT_ALL);
ASSERT_EQ(7u, results.size());
EXPECT_THAT(results, ElementsAre("uno", "", "", "dos", "tres", "", "cuatro"));
}
TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) {
std::vector<std::string> results;
SplitStringUsingSubstr(
std::vector<std::string> results = SplitStringUsingSubstr(
"unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER",
"DELIMITER",
&results);
"DELIMITER", TRIM_WHITESPACE, SPLIT_WANT_ALL);
ASSERT_EQ(7u, results.size());
EXPECT_THAT(
results, ElementsAre("un", "deux", "trois", "quatre", "", "", ""));
......
......@@ -283,8 +283,8 @@ void ReceivedResponse(const AndroidDeviceManager::DeviceInfoCallback& callback,
callback.Run(device_info);
return;
}
std::vector<std::string> outputs;
base::SplitStringUsingSubstr(response, kSeparator, &outputs);
std::vector<std::string> outputs = base::SplitStringUsingSubstr(
response, kSeparator, base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (outputs.size() != 5) {
callback.Run(device_info);
return;
......
......@@ -101,8 +101,8 @@ autofill_private::AddressEntry ProfileToAddressEntry(
// Parse |label| so that it can be used to create address metadata.
base::string16 separator =
l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR);
std::vector<base::string16> label_pieces;
base::SplitStringUsingSubstr(label, separator, &label_pieces);
std::vector<base::string16> label_pieces = base::SplitStringUsingSubstr(
label, separator, base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
// Create address metadata and add it to |address|.
std::unique_ptr<autofill_private::AutofillMetadata> metadata(
......
......@@ -301,8 +301,8 @@ IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) {
EXPECT_NE(std::string::npos, log_part.find("Cpu brand:"));
// Check the multipart contents.
std::vector<std::string> multipart_lines;
base::SplitStringUsingSubstr(multipart, "\r\n", &multipart_lines);
std::vector<std::string> multipart_lines = base::SplitStringUsingSubstr(
multipart, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
ASSERT_EQ(31, static_cast<int>(multipart_lines.size()));
EXPECT_STREQ(&boundary[0], multipart_lines[0].c_str());
......
......@@ -149,8 +149,8 @@ class WebRtcLogUploaderTest : public testing::Test {
void VerifyRtpDumpInMultipart(const std::string& post_data,
const std::string& dump_name,
const std::string& dump_content) {
std::vector<std::string> lines;
base::SplitStringUsingSubstr(post_data, "\r\n", &lines);
std::vector<std::string> lines = base::SplitStringUsingSubstr(
post_data, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
std::string name_line = "Content-Disposition: form-data; name=\"";
name_line.append(dump_name);
......
......@@ -98,8 +98,8 @@ bool GetInt64Param(const std::map<std::string, std::string>& params,
// Parses the key. e.g.: "PerfCommand::arm::0" returns "arm"
bool ExtractPerfCommandCpuSpecifier(const std::string& key,
std::string* cpu_specifier) {
std::vector<std::string> tokens;
base::SplitStringUsingSubstr(key, "::", &tokens);
std::vector<std::string> tokens = base::SplitStringUsingSubstr(
key, "::", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (tokens.size() != 3)
return false;
if (tokens[0] != "PerfCommand")
......
......@@ -346,8 +346,8 @@ void AutofillOptionsHandler::LoadAutofillData() {
base::string16 separator =
l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR);
std::vector<base::string16> label_parts;
base::SplitStringUsingSubstr(labels[i], separator, &label_parts);
std::vector<base::string16> label_parts = base::SplitStringUsingSubstr(
labels[i], separator, base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
value->SetString("guid", profiles[i]->guid());
......
......@@ -26,22 +26,30 @@ void CheckUserAgentStringOrdering(bool mobile_device) {
ChromeContentClient content_client;
std::string buffer = content_client.GetUserAgent();
base::SplitStringUsingSubstr(buffer, "Mozilla/5.0 (", &pieces);
pieces = base::SplitStringUsingSubstr(buffer, "Mozilla/5.0 (",
base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL);
ASSERT_EQ(2u, pieces.size());
buffer = pieces[1];
EXPECT_EQ("", pieces[0]);
base::SplitStringUsingSubstr(buffer, ") AppleWebKit/", &pieces);
pieces = base::SplitStringUsingSubstr(buffer, ") AppleWebKit/",
base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL);
ASSERT_EQ(2u, pieces.size());
buffer = pieces[1];
std::string os_str = pieces[0];
base::SplitStringUsingSubstr(buffer, " (KHTML, like Gecko) ", &pieces);
pieces = base::SplitStringUsingSubstr(buffer, " (KHTML, like Gecko) ",
base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL);
ASSERT_EQ(2u, pieces.size());
buffer = pieces[1];
std::string webkit_version_str = pieces[0];
base::SplitStringUsingSubstr(buffer, " Safari/", &pieces);
pieces = base::SplitStringUsingSubstr(buffer, " Safari/",
base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL);
ASSERT_EQ(2u, pieces.size());
std::string product_str = pieces[0];
std::string safari_version_str = pieces[1];
......
......@@ -40,15 +40,15 @@ StackTrace GetStackTraceFromMessage(base::string16* message,
if (message->find(base::UTF8ToUTF16(kStackFrameDelimiter)) !=
base::string16::npos) {
base::SplitStringUsingSubstr(*message,
base::UTF8ToUTF16(kStackFrameDelimiter),
&pieces);
pieces = base::SplitStringUsingSubstr(
*message, base::UTF8ToUTF16(kStackFrameDelimiter),
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
*message = pieces[0];
index = 1;
} else if (!stack_trace.empty()) {
base::SplitStringUsingSubstr(stack_trace,
base::UTF8ToUTF16(kStackFrameDelimiter),
&pieces);
pieces = base::SplitStringUsingSubstr(
stack_trace, base::UTF8ToUTF16(kStackFrameDelimiter),
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
}
// If we got a stack trace, parse each frame from the text.
......
......@@ -45,8 +45,8 @@ int ParseListing(const base::string16& text,
const base::Time& current_time,
std::vector<FtpDirectoryListingEntry>* entries,
FtpServerType* server_type) {
std::vector<base::string16> lines;
base::SplitStringUsingSubstr(text, newline_separator, &lines);
std::vector<base::string16> lines = base::SplitStringUsingSubstr(
text, newline_separator, base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
struct {
base::Callback<bool(void)> callback;
......
......@@ -69,8 +69,8 @@ TEST_P(FtpDirectoryListingParserTest, Parse) {
test_dir.AppendASCII(std::string(param.name) + ".expected"),
&expected_listing));
std::vector<std::string> lines;
base::SplitStringUsingSubstr(expected_listing, "\r\n", &lines);
std::vector<std::string> lines = base::SplitStringUsingSubstr(
expected_listing, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
// Special case for empty listings.
if (lines.size() == 1 && lines[0].empty())
......
......@@ -1036,16 +1036,17 @@ void GesturePropertyProvider::ParseXorgConfFile(const std::string& content) {
// Sections are delimited by the "EndSection" keyword.
// Lines are delimited by "\n".
// Pieces are delimited by all white-spaces.
std::vector<std::string> sections;
base::SplitStringUsingSubstr(content, "EndSection", &sections);
for (size_t i = 0; i < sections.size(); ++i) {
for (const std::string& section :
base::SplitStringUsingSubstr(content, "EndSection",
base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL)) {
// Create a new configuration section.
configurations_.push_back(
base::MakeUnique<internal::ConfigurationSection>());
internal::ConfigurationSection* config = configurations_.back().get();
// Break the section into lines.
base::StringTokenizer lines(sections[i], "\n");
base::StringTokenizer lines(section, "\n");
bool is_input_class_section = true;
bool has_checked_section_type = false;
while (is_input_class_section && lines.GetNext()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment