summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorCasey Dahlin <sadmac@google.com>2015-11-02 20:28:09 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-11-02 20:28:09 +0000
commit46776e7423c9a4a7ed5f52def545feee4c31297c (patch)
tree299c4cfcc321e149b19272827948cb6f62bce3f5 /base
parent5c75b529f684b388c91c7e7d0b2c7fece376ac1d (diff)
parent5345f1df0d83ec08cf156584d32d425ee9f941e5 (diff)
downloadcore-46776e7423c9a4a7ed5f52def545feee4c31297c.tar.gz
core-46776e7423c9a4a7ed5f52def545feee4c31297c.tar.bz2
core-46776e7423c9a4a7ed5f52def545feee4c31297c.zip
Merge "Make Join support string delimiters"
Diffstat (limited to 'base')
-rw-r--r--base/include/base/strings.h6
-rw-r--r--base/strings.cpp2
2 files changed, 6 insertions, 2 deletions
diff --git a/base/include/base/strings.h b/base/include/base/strings.h
index 638f845db..20da144a4 100644
--- a/base/include/base/strings.h
+++ b/base/include/base/strings.h
@@ -36,8 +36,8 @@ std::vector<std::string> Split(const std::string& s,
std::string Trim(const std::string& s);
// Joins a container of things into a single string, using the given separator.
-template <typename ContainerT>
-std::string Join(const ContainerT& things, char separator) {
+template <typename ContainerT, typename SeparatorT>
+std::string Join(const ContainerT& things, SeparatorT separator) {
if (things.empty()) {
return "";
}
@@ -53,6 +53,8 @@ std::string Join(const ContainerT& things, char separator) {
// We instantiate the common cases in strings.cpp.
extern template std::string Join(const std::vector<std::string>&, char);
extern template std::string Join(const std::vector<const char*>&, char);
+extern template std::string Join(const std::vector<std::string>&, const std::string&);
+extern template std::string Join(const std::vector<const char*>&, const std::string&);
// Tests whether 's' starts with 'prefix'.
bool StartsWith(const std::string& s, const char* prefix);
diff --git a/base/strings.cpp b/base/strings.cpp
index bac983b01..d687e3cf6 100644
--- a/base/strings.cpp
+++ b/base/strings.cpp
@@ -83,6 +83,8 @@ std::string Trim(const std::string& s) {
// aid compile time and binary size.
template std::string Join(const std::vector<std::string>&, char);
template std::string Join(const std::vector<const char*>&, char);
+template std::string Join(const std::vector<std::string>&, const std::string&);
+template std::string Join(const std::vector<const char*>&, const std::string&);
bool StartsWith(const std::string& s, const char* prefix) {
return s.compare(0, strlen(prefix), prefix) == 0;