Make Join support string delimiters
We've needed this several times in the past. Change-Id: I7324e8083fe2ff1aa0bf392a8c124fc2f3bb26e2 Test: Full android build Signed-off-by: Casey Dahlin <sadmac@google.com>
This commit is contained in:
parent
24704399cd
commit
5345f1df0d
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue