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,
const std::string& delim) {
55 std::vector< std::string > tokens;
56 size_t prev = 0, pos = 0;
58 pos = str.find(delim, prev);
59 if (pos == std::string::npos) pos = str.length();
60 std::string token = str.substr(prev, pos - prev);
61 if (!token.empty()) tokens.push_back(token);
62 prev = pos + delim.length();
63 }
while (pos < str.length() && prev < str.length());
78 std::string replace(
const std::string& s,
const std::string& val,
const std::string& new_val) {
80 auto pos = retVal.find(val);
81 while (pos != std::string::npos) {
82 std::stringstream sBuff;
83 sBuff << s.substr(0, pos) << new_val << s.substr(pos + val.size(), std::string::npos);
85 pos = retVal.find(val);
93 # include <agrum/tools/core/utils_string_inl.h>