52 lines
919 B
C++
52 lines
919 B
C++
#include "extstring.h"
|
|
|
|
namespace segl {
|
|
|
|
int explode(std::string str, std::string delim, std::vector<std::string> *erg, bool clean) {
|
|
erg->clear();
|
|
|
|
int treffer=0;
|
|
std::string tmp;
|
|
unsigned int pos;
|
|
|
|
while((pos = str.find(delim))!=std::string::npos) {
|
|
tmp = str.substr(0, pos);
|
|
|
|
if(!clean || tmp!="") {
|
|
// tmp nicht leer, hinzufügen
|
|
erg->push_back(tmp);
|
|
treffer++;
|
|
}
|
|
|
|
str = str.substr(pos+1); // alten kram entfernen
|
|
}
|
|
|
|
if(str.length()>0) {
|
|
treffer++;
|
|
erg->push_back(str);
|
|
}
|
|
|
|
return treffer;
|
|
}
|
|
|
|
std::string trim(std::string t) {
|
|
while(t.length() && isspace(t[0])) {
|
|
t = t.substr(1);
|
|
}
|
|
|
|
while(t.length() && ( isspace(t[t.length()-1]) )) {
|
|
t = t.substr(0, t.length()-2);
|
|
}
|
|
return t;
|
|
}
|
|
|
|
std::string basename(std::string str) {
|
|
return str.substr( str.rfind("/"));
|
|
}
|
|
|
|
std::string rbasename(std::string str) {
|
|
return str.substr(0, str.rfind("/")+1);
|
|
}
|
|
|
|
} // namespace segl
|