libchromeos: Replace char with std::string in string_utils API
std::string version of functions is enough to cover char use cases.
C library was replaced with STL in Split and SplitAtFirst implementations.
Added support of splitting by empty string. Uses but reasonable implementation
is simple.
BUG=none
TEST=unittests
Change-Id: I0778722d31a7b06eea2227b4d94991ab194195cb
Reviewed-on: https://chromium-review.googlesource.com/258640
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/command_dictionary.cc b/buffet/commands/command_dictionary.cc
index 1dd0407..14bead8 100644
--- a/buffet/commands/command_dictionary.cc
+++ b/buffet/commands/command_dictionary.cc
@@ -64,8 +64,8 @@
return false;
}
// Construct the compound command name as "pkg_name.cmd_name".
- std::string full_command_name = chromeos::string_utils::Join(
- '.', package_name, command_name);
+ std::string full_command_name =
+ chromeos::string_utils::Join(".", package_name, command_name);
const ObjectSchema* base_parameters_def = nullptr;
const ObjectSchema* base_results_def = nullptr;
@@ -186,7 +186,7 @@
dict.reset();
return dict;
}
- auto cmd_name_parts = chromeos::string_utils::SplitAtFirst(pair.first, '.');
+ auto cmd_name_parts = chromeos::string_utils::SplitAtFirst(pair.first, ".");
std::string package_name = cmd_name_parts.first;
std::string command_name = cmd_name_parts.second;
base::DictionaryValue* package = nullptr;
diff --git a/buffet/commands/command_queue_unittest.cc b/buffet/commands/command_queue_unittest.cc
index 97431b8..12c5500 100644
--- a/buffet/commands/command_queue_unittest.cc
+++ b/buffet/commands/command_queue_unittest.cc
@@ -52,7 +52,7 @@
// command queue.
std::string GetIDs() const {
using chromeos::string_utils::Join;
- return Join(',', std::vector<std::string>(ids_.begin(), ids_.end()));
+ return Join(",", std::vector<std::string>(ids_.begin(), ids_.end()));
}
private:
@@ -107,7 +107,7 @@
queue.Add(CreateDummyCommandInstance("base.reboot", id2));
std::set<std::string> ids{id1, id2}; // Make sure they are sorted properly.
std::string expected_set = chromeos::string_utils::Join(
- ',', std::vector<std::string>(ids.begin(), ids.end()));
+ ",", std::vector<std::string>(ids.begin(), ids.end()));
EXPECT_EQ(expected_set, dispatch.GetIDs());
queue.Remove(id1);
EXPECT_EQ(id2, dispatch.GetIDs());
diff --git a/buffet/commands/prop_constraints.cc b/buffet/commands/prop_constraints.cc
index 641d0f6..ff01e05 100644
--- a/buffet/commands/prop_constraints.cc
+++ b/buffet/commands/prop_constraints.cc
@@ -37,12 +37,11 @@
bool Constraint::ReportErrorNotOneOf(chromeos::ErrorPtr* error,
const std::string& val,
const std::vector<std::string>& values) {
- chromeos::Error::AddToPrintf(error, FROM_HERE, errors::commands::kDomain,
- errors::commands::kOutOfRange,
- "Value %s is invalid. Expected one of [%s]",
- val.c_str(),
- chromeos::string_utils::Join(',',
- values).c_str());
+ chromeos::Error::AddToPrintf(
+ error, FROM_HERE, errors::commands::kDomain,
+ errors::commands::kOutOfRange,
+ "Value %s is invalid. Expected one of [%s]", val.c_str(),
+ chromeos::string_utils::Join(",", values).c_str());
return false;
}
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index ff4df89..78b72a5 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -65,7 +65,7 @@
const std::string& access_token_type,
const std::string& access_token) {
std::string authorization =
- chromeos::string_utils::Join(' ', access_token_type, access_token);
+ chromeos::string_utils::Join(" ", access_token_type, access_token);
return {chromeos::http::request_header::kAuthorization, authorization};
}
diff --git a/buffet/states/state_manager.cc b/buffet/states/state_manager.cc
index d98015d..827cd7f 100644
--- a/buffet/states/state_manager.cc
+++ b/buffet/states/state_manager.cc
@@ -111,7 +111,7 @@
std::string package_name;
std::string property_name;
bool split = chromeos::string_utils::SplitAtFirst(
- full_property_name, '.', &package_name, &property_name);
+ full_property_name, ".", &package_name, &property_name);
if (full_property_name.empty() || (split && property_name.empty())) {
chromeos::Error::AddTo(error, FROM_HERE, errors::state::kDomain,
errors::state::kPropertyNameMissing,