mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 14:55:20 +00:00
Better string split implementation
This commit is contained in:
@@ -217,14 +217,14 @@ string &replace_all(string &str, string_view from, string_view to) {
|
||||
return str;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static auto split_impl(T s, T delims) {
|
||||
vector<std::decay_t<T>> result;
|
||||
template <typename T>
|
||||
static auto split_impl(string_view s, string_view delims) {
|
||||
vector<T> result;
|
||||
size_t base = 0;
|
||||
size_t found;
|
||||
while (true) {
|
||||
found = s.find_first_of(delims, base);
|
||||
result.push_back(s.substr(base, found - base));
|
||||
result.emplace_back(s.substr(base, found - base));
|
||||
if (found == string::npos)
|
||||
break;
|
||||
base = found + 1;
|
||||
@@ -232,11 +232,11 @@ static auto split_impl(T s, T delims) {
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<string> split(const string &s, const string &delims) {
|
||||
return split_impl<const string&>(s, delims);
|
||||
vector<string> split(string_view s, string_view delims) {
|
||||
return split_impl<string>(s, delims);
|
||||
}
|
||||
|
||||
vector<string_view> split_ro(string_view s, string_view delims) {
|
||||
vector<string_view> split_view(string_view s, string_view delims) {
|
||||
return split_impl<string_view>(s, delims);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,8 +163,8 @@ int switch_mnt_ns(int pid);
|
||||
std::mt19937_64 &get_rand(const void *seed_buf = nullptr);
|
||||
int gen_rand_str(char *buf, int len, bool varlen = true);
|
||||
std::string &replace_all(std::string &str, std::string_view from, std::string_view to);
|
||||
std::vector<std::string> split(const std::string &s, const std::string &delims);
|
||||
std::vector<std::string_view> split_ro(std::string_view, std::string_view delims);
|
||||
std::vector<std::string> split(std::string_view s, std::string_view delims);
|
||||
std::vector<std::string_view> split_view(std::string_view, std::string_view delims);
|
||||
|
||||
// Similar to vsnprintf, but the return value is the written number of bytes
|
||||
int vssprintf(char *dest, size_t size, const char *fmt, va_list ap);
|
||||
|
||||
Reference in New Issue
Block a user