libchromeos: Migrate string_utils from Buffet to libchromeos
BUG=chromium:405714
TEST=USE=buffet ./build_packages
Change-Id: I95d8977aed6ffd718751de058d4cdda3a5395c25
Reviewed-on: https://chromium-review.googlesource.com/213361
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_dictionary.cc b/buffet/commands/command_dictionary.cc
index 64f47c1..54753ad 100644
--- a/buffet/commands/command_dictionary.cc
+++ b/buffet/commands/command_dictionary.cc
@@ -5,10 +5,10 @@
#include "buffet/commands/command_dictionary.h"
#include <base/values.h>
+#include <chromeos/string_utils.h>
#include "buffet/commands/command_definition.h"
#include "buffet/commands/schema_constants.h"
-#include "buffet/string_utils.h"
namespace buffet {
@@ -63,8 +63,8 @@
return false;
}
// Construct the compound command name as "pkg_name.cmd_name".
- std::string full_command_name = string_utils::Join('.', package_name,
- command_name);
+ std::string full_command_name = chromeos::string_utils::Join(
+ '.', package_name, command_name);
// Get the "parameters" definition of the command and read it into
// an object schema.
const base::DictionaryValue* command_schema_def = nullptr;
@@ -158,7 +158,7 @@
dict.reset();
return dict;
}
- auto cmd_name_parts = 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 2c0e01b..a9d5ad9 100644
--- a/buffet/commands/command_queue_unittest.cc
+++ b/buffet/commands/command_queue_unittest.cc
@@ -6,11 +6,11 @@
#include <string>
#include <vector>
+#include <chromeos/string_utils.h>
#include <gtest/gtest.h>
#include "buffet/commands/command_dispatch_interface.h"
#include "buffet/commands/command_queue.h"
-#include "buffet/string_utils.h"
namespace {
@@ -46,7 +46,7 @@
// Get the comma-separated list of command IDs currently accumulated in the
// command queue.
std::string GetIDs() const {
- using buffet::string_utils::Join;
+ using chromeos::string_utils::Join;
return Join(',', std::vector<std::string>(ids_.begin(), ids_.end()));
}
@@ -99,7 +99,7 @@
std::string id1 = queue.Add(CreateDummyCommandInstance());
std::string id2 = queue.Add(CreateDummyCommandInstance());
std::set<std::string> ids{id1, id2}; // Make sure they are sorted properly.
- std::string expected_set = buffet::string_utils::Join(
+ std::string expected_set = chromeos::string_utils::Join(
',', std::vector<std::string>(ids.begin(), ids.end()));
EXPECT_EQ(expected_set, dispatch.GetIDs());
queue.Remove(id1);
diff --git a/buffet/commands/prop_constraints.cc b/buffet/commands/prop_constraints.cc
index 210b254..c9008d2 100644
--- a/buffet/commands/prop_constraints.cc
+++ b/buffet/commands/prop_constraints.cc
@@ -5,7 +5,6 @@
#include "buffet/commands/prop_constraints.h"
#include "buffet/commands/prop_values.h"
#include "buffet/commands/schema_constants.h"
-#include "buffet/string_utils.h"
namespace buffet {
@@ -41,7 +40,8 @@
errors::commands::kOutOfRange,
"Value %s is invalid. Expected one of [%s]",
val.c_str(),
- string_utils::Join(',', values).c_str());
+ chromeos::string_utils::Join(',',
+ values).c_str());
return false;
}
diff --git a/buffet/commands/prop_constraints.h b/buffet/commands/prop_constraints.h
index 3aa6e8e..e765f44 100644
--- a/buffet/commands/prop_constraints.h
+++ b/buffet/commands/prop_constraints.h
@@ -12,11 +12,11 @@
#include <base/basictypes.h>
#include <base/values.h>
#include <chromeos/error.h>
+#include <chromeos/string_utils.h>
#include "buffet/commands/prop_values.h"
#include "buffet/commands/schema_constants.h"
#include "buffet/commands/schema_utils.h"
-#include "buffet/string_utils.h"
namespace buffet {
@@ -138,8 +138,8 @@
T v = value.GetValueAsAny().Get<T>();
if (v < this->limit_.value)
return this->ReportErrorLessThan(
- error, string_utils::ToString(v),
- string_utils::ToString(this->limit_.value));
+ error, chromeos::string_utils::ToString(v),
+ chromeos::string_utils::ToString(this->limit_.value));
return true;
}
@@ -175,8 +175,8 @@
T v = value.GetValueAsAny().Get<T>();
if (v > this->limit_.value)
return this->ReportErrorGreaterThan(
- error, string_utils::ToString(v),
- string_utils::ToString(this->limit_.value));
+ error, chromeos::string_utils::ToString(v),
+ chromeos::string_utils::ToString(this->limit_.value));
return true;
}
@@ -282,7 +282,7 @@
// Implementation of Constraint::Validate().
bool Validate(const PropValue& value,
chromeos::ErrorPtr* error) const override {
- using string_utils::ToString;
+ using chromeos::string_utils::ToString;
T v = value.GetValueAsAny().Get<T>();
for (const auto& item : set_.value) {
if (CompareValue(v, item))
diff --git a/buffet/commands/prop_types.cc b/buffet/commands/prop_types.cc
index a3d7d6c..505dd5d 100644
--- a/buffet/commands/prop_types.cc
+++ b/buffet/commands/prop_types.cc
@@ -11,11 +11,11 @@
#include <base/json/json_writer.h>
#include <base/logging.h>
#include <base/values.h>
+#include <chromeos/string_utils.h>
#include "buffet/commands/object_schema.h"
#include "buffet/commands/prop_values.h"
#include "buffet/commands/schema_constants.h"
-#include "buffet/string_utils.h"
namespace buffet {