vvb2060
2021-05-26 01:21:54 +08:00
committed by John Wu
parent 34e5a7cd24
commit 79e8962854
4 changed files with 97 additions and 39 deletions

View File

@@ -188,3 +188,16 @@ string &replace_all(string &str, string_view from, string_view to) {
}
return str;
}
vector<string> split(const string& s, const string& delimiters) {
vector<string> result;
size_t base = 0;
size_t found;
while (true) {
found = s.find_first_of(delimiters, base);
result.push_back(s.substr(base, found - base));
if (found == string::npos) break;
base = found + 1;
}
return result;
}

View File

@@ -92,6 +92,18 @@ static inline bool str_starts(std::string_view s, std::string_view ss) {
static inline bool str_ends(std::string_view s, std::string_view ss) {
return s.size() >= ss.size() && s.compare(s.size() - ss.size(), std::string::npos, ss) == 0;
}
static inline std::string ltrim(std::string &&s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
return std::move(s);
}
static inline std::string rtrim(std::string &&s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch) && ch != '\0';
}).base(), s.end());
return std::move(s);
}
int fork_dont_care();
int fork_no_orphan();
@@ -101,6 +113,7 @@ uint32_t binary_gcd(uint32_t u, uint32_t v);
int switch_mnt_ns(int pid);
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& delimiters);
struct exec_t {
bool err = false;