27 #include <sys/types.h>
41 if(prefix.size() > str.size())
return str;
43 if(std::equal(prefix.begin(), prefix.end(), str.begin())) {
44 return str.substr(prefix.size(), str.size()-prefix.size());
51 while(str.size() > 0 && str[str.size()-1] ==
'/') {
52 str.erase(str.size()-1);
57 inline std::string
join(
const std::string &separator,
const std::vector<std::string> &arr) {
58 if(arr.empty())
return std::string();
61 for(
size_t i = 0; i < arr.size()-1; i++) {
65 ss << arr[arr.size()-1];
69 inline std::vector<std::string>
split(std::string data, std::string token) {
70 std::vector<std::string> output;
71 size_t pos = std::string::npos;
73 pos = data.find(token);
74 output.push_back(data.substr(0, pos));
75 if(std::string::npos != pos)
76 data = data.substr(pos + token.size());
77 }
while (std::string::npos != pos);
81 inline std::vector<std::string>
rsplit(std::string data, std::string token,
int max=-1) {
82 std::vector<std::string> output;
83 for (
int cnt = 0; ; cnt++) {
84 size_t start = data.rfind(token);
85 if (start == std::string::npos || cnt == max) {
86 output.insert(output.begin(), data.substr(0, data.length()));
89 output.insert(output.begin(), data.substr(start+token.length(), data.length()-start));
90 data = data.substr(0, start);
95 inline void mkdirp(
const std::string& path) {
96 std::vector<std::string> parts =
split(path,
"/");
97 std::ostringstream tocreate(parts[0]);
100 for(std::vector<std::string>::iterator it = parts.begin()+1; it+1 != parts.end(); it++) {
101 tocreate <<
"/" + *it;
104 if(::stat(tocreate.str().c_str(), &info) != 0) {
107 mode_t prev = umask(0);
108 int ret = ::mkdir(tocreate.str().c_str(), 0770);
114 throw DmException(errno,
"Could not create directory: '%s' err: %d:'%s'", tocreate.str().c_str(), errno, errbuffer);
128 if(str ==
"false" || str ==
"0" || str ==
"no") {
130 }
else if(str ==
"true" || str ==
"1" || str ==
"yes") {
137 size_t pos = rfn.find(
":");
138 if(pos == std::string::npos)
140 return rfn.substr(pos+1, rfn.size());
144 size_t pos = rfn.find(
":");
145 if(pos == std::string::npos)
147 return rfn.substr(0, pos);
151 std::ostringstream ss;
152 for(
size_t i = 0; i < str.size(); i++) {
153 if(i != str.size()-1 && str[i] ==
'\\' && str[i+1] ==
'/') {