32 #include <agrum/tools/core/utils_string.h> 36 std::string getUniqueFileName() {
38 char tmpFileName_[] =
"fileXXXXXX";
39 int fd = mkstemp(tmpFileName_);
42 char tmpFileName_[] =
"fileXXXXXX";
43 _mktemp_s(tmpFileName_, strlen(tmpFileName_));
46 return std::string(tmpFileName_);
49 bool endsWith(std::string
const& value, std::string
const& ending) {
50 if (ending.size() > value.size())
return false;
51 return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
54 std::vector< std::string > split(
const std::string& str,
55 const std::string& delim) {
56 std::vector< std::string > tokens;
57 size_t prev = 0, pos = 0;
59 pos = str.find(delim, prev);
60 if (pos == std::string::npos) pos = str.length();
61 std::string token = str.substr(prev, pos - prev);
62 if (!token.empty()) tokens.push_back(token);
63 prev = pos + delim.length();
64 }
while (pos < str.length() && prev < str.length());
79 std::string replace(
const std::string& s,
80 const std::string& val,
81 const std::string& new_val) {
83 auto pos = retVal.find(val);
84 while (pos != std::string::npos) {
85 std::stringstream sBuff;
86 sBuff << s.substr(0, pos) << new_val
87 << s.substr(pos + val.size(), std::string::npos);
89 pos = retVal.find(val);
97 # include <agrum/tools/core/utils_string_inl.h>