#pragma once
#include <sstream>
#include <string>
#include <string_view>
#include <vector>
namespace android {
namespace base {
std::vector<std::string> Split(const std::string& s,
const std::string& delimiters);
std::string Trim(const std::string& s);
template <typename ContainerT, typename SeparatorT>
std::string Join(const ContainerT& things, SeparatorT separator) {
if (things.empty()) {
return "";
}
std::ostringstream result;
result << *things.begin();
for (auto it = std::next(things.begin()); it != things.end(); ++it) {
result << separator << *it;
}
return result.str();
}
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&);
bool StartsWith(std::string_view s, std::string_view prefix);
bool StartsWith(std::string_view s, char prefix);
bool StartsWithIgnoreCase(std::string_view s, std::string_view prefix);
bool EndsWith(std::string_view s, std::string_view suffix);
bool EndsWith(std::string_view s, char suffix);
bool EndsWithIgnoreCase(std::string_view s, std::string_view suffix);
bool EqualsIgnoreCase(std::string_view lhs, std::string_view rhs);
inline bool ConsumePrefix(std::string_view* s, std::string_view prefix) {
if (!StartsWith(*s, prefix)) return false;
s->remove_prefix(prefix.size());
return true;
}
inline bool ConsumeSuffix(std::string_view* s, std::string_view suffix) {
if (!EndsWith(*s, suffix)) return false;
s->remove_suffix(suffix.size());
return true;
}
[[nodiscard]] std::string StringReplace(std::string_view s, std::string_view from,
std::string_view to, bool all);
} }