1234567891011121314151617181920212223242526272829303132333435363738 |
- /*!
- * \file src/utils/strings.cpp
- * \brief String handling utilities
- *
- * \author xythobuz
- */
-
- #include "global.h"
- #include "utils/filesystem.h"
- #include "utils/strings.h"
-
- std::string findAndReplace(std::string s, std::string find, std::string replace) {
- size_t p = s.find(find);
- while (p != std::string::npos) {
- s.erase(p, find.length());
- s.insert(p, replace);
- p = s.find(find);
- }
- return s;
- }
-
- std::string expandHomeDirectory(std::string s) {
- if ((s.length() > 0) && (s[0] == '~')) {
- s.erase(0, 1);
- s.insert(0, getHomeDirectory());
- }
- return s;
- }
-
- bool stringEndsWith(std::string s, std::string suffix) {
- if (s.length() >= suffix.length()) {
- std::string end = s.substr(s.length() - suffix.length());
- return (end == suffix);
- }
-
- return false;
- }
|