Line data Source code
1 : #include "utils/string.hpp" 2 : 3 : using namespace std; 4 : 5 0 : bool utils::ends_with(const string &s, const string &p) { 6 0 : return s.compare(s.length() - p.length(), p.length(), p) == 0; 7 : } 8 : 9 0 : vector<string> utils::split(const string &s, const string &delim) { 10 0 : vector<string> result; 11 : 12 0 : size_t start = 0; 13 0 : size_t end = s.find(delim); 14 : 15 0 : while(end != string::npos) { 16 0 : result.emplace_back(s.substr(start, end - start)); 17 0 : start = end + delim.length(); 18 0 : end = s.find(delim, start); 19 : } 20 : 21 0 : result.emplace_back(s.substr(start, end)); 22 : 23 0 : return result; 24 : }