summaryrefslogtreecommitdiffstats
path: root/base/strings.cpp
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-05-21 18:37:36 -0700
committerDan Albert <danalbert@google.com>2015-05-22 10:07:06 -0700
commite0da8a1d377c22d1956376302294ee988b44fd47 (patch)
tree0813d979ad3b68c1e0269f7caca54651b8933471 /base/strings.cpp
parent3ff23e2461de5a5aae4343147486df84e8a77d90 (diff)
downloadcore-e0da8a1d377c22d1956376302294ee988b44fd47.tar.gz
core-e0da8a1d377c22d1956376302294ee988b44fd47.tar.bz2
core-e0da8a1d377c22d1956376302294ee988b44fd47.zip
Generalize Join to work for any container/element.
This is more scalable than explicitly instantiating templates for the cross product of containers and element types. Specifically I'm adding this so I can join an unordered_set in adb. Change-Id: I0055f3390a0ff26a886a0d41bbf0d4fe3d210f9c
Diffstat (limited to 'base/strings.cpp')
-rw-r--r--base/strings.cpp23
1 files changed, 4 insertions, 19 deletions
diff --git a/base/strings.cpp b/base/strings.cpp
index d3375d9fa..bac983b01 100644
--- a/base/strings.cpp
+++ b/base/strings.cpp
@@ -79,25 +79,10 @@ std::string Trim(const std::string& s) {
return s.substr(start_index, end_index - start_index + 1);
}
-template <typename StringT>
-std::string Join(const std::vector<StringT>& strings, char separator) {
- if (strings.empty()) {
- return "";
- }
-
- std::string result(strings[0]);
- for (size_t i = 1; i < strings.size(); ++i) {
- result += separator;
- result += strings[i];
- }
- return result;
-}
-
-// Explicit instantiations.
-template std::string Join<std::string>(const std::vector<std::string>& strings,
- char separator);
-template std::string Join<const char*>(const std::vector<const char*>& strings,
- char separator);
+// These cases are probably the norm, so we mark them extern in the header to
+// 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);
bool StartsWith(const std::string& s, const char* prefix) {
return s.compare(0, strlen(prefix), prefix) == 0;