Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5345f1df authored by Casey Dahlin's avatar Casey Dahlin
Browse files

Make Join support string delimiters



We've needed this several times in the past.

Change-Id: I7324e8083fe2ff1aa0bf392a8c124fc2f3bb26e2
Test: Full android build
Signed-off-by: default avatarCasey Dahlin <sadmac@google.com>
parent 24704399
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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);
+2 −0
Original line number Diff line number Diff line
@@ -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;