vector<string> split(const string& s, const string& delim, const string& stripchars="", bool drop_empty=false){ vector<string> result; int b = 0; int e = 0; int i = b; int state = 0; do { bool isspace = (stripchars.find(s[i]) != -1); bool isdelim = (s[i]=='\0' || delim.find(s[i]) != -1); switch(state) { case0: if(isdelim) { if(e != b || !drop_empty) { result.emplace_back(string(&s[b], &s[e])); } state = 0; e = b = i + 1; } elseif(isspace) { state = 1; e = b = i + 1; } else { state = 2; e = i + 1; } break; case1: if(isdelim) { if(e != b || !drop_empty) { result.emplace_back(string(&s[b], &s[e])); } state = 0; e = b = i + 1; } elseif(isspace) { state = 1; e = b = i + 1; } else { state = 2; e = i + 1; } break; case2: if(isdelim) { if(e != b || !drop_empty) { result.emplace_back(string(&s[b], &s[e])); } state = 0; e = b = i + 1; } elseif(isspace) { state = 3; } else { state = 2; e = i + 1; } break; default: if(isdelim) { if(e != b || !drop_empty) { result.emplace_back(string(&s[b], &s[e])); } state = 0; e = b = i + 1; } elseif(isspace) { state = 3; } else { state = 2; e = i + 1; } break; } if(s[i]=='\0') break; i++; } while(true); return result; }