str2parts.cc (757B)
1 #include "sys" 2 #include "config/config" 3 4 vector<string> str2parts (string const &s, char sep) { 5 PROFILE("str2parts"); 6 7 string str = s; 8 size_t pos; 9 vector<string> parts; 10 11 bool sep_is_first = false; 12 while ( (pos = str.find_first_of(sep)) != string::npos) { 13 if (!pos) { 14 sep_is_first = true; 15 parts.push_back(""); 16 } else { 17 sep_is_first = true; 18 parts.push_back (str.substr(0, pos)); 19 } 20 str = str.substr(pos + 1); 21 } 22 if (str.length() > 0) 23 parts.push_back (str); 24 else if (sep_is_first) 25 parts.push_back(""); 26 27 /* 28 ostringstream o; 29 o << "str2parts: "; 30 for (unsigned int i = 0; i < parts.size(); i++) 31 o << "[" << parts[i] << "] "; 32 o << "\n"; 33 _debugmsg(o.str()); 34 */ 35 36 return (parts); 37 }