all repos — fluxbox @ a9f9e6d6eec6a42921e4446baef92eb5b2356d60

custom fork of the fluxbox windowmanager

added replaceString
fluxgen fluxgen
commit

a9f9e6d6eec6a42921e4446baef92eb5b2356d60

parent

4dec832b6bcef0503ac092a8cfdc370ab65f8f8f

2 files changed, 30 insertions(+), 1 deletions(-)

jump to
M src/FbTk/StringUtil.ccsrc/FbTk/StringUtil.cc

@@ -23,7 +23,7 @@ // $Id$

#include "StringUtil.hh" -#include <string> + #ifdef HAVE_CSTDIO #include <cstdio> #else

@@ -44,8 +44,11 @@ #include <cassert>

#else #include <assert.h> #endif + + #include <memory> #include <algorithm> +#include <string> using namespace std;

@@ -114,6 +117,27 @@ if (start_pos == std::string::npos && start_pos != filename.size())

return ""; // return from last . to end of string return filename.substr(start_pos + 1); +} + +string replaceString(const std::string &original, + const char *findthis, + const char *replace) { + int i=0; + const int size_of_replace = strlen(replace); + const int size_of_find = strlen(findthis); + string ret_str(original); + while (i < ret_str.size()) { + i = ret_str.find(findthis, i); + if (i == std::string::npos) + break; + // erase old string and insert replacement + ret_str.erase(i, size_of_find); + ret_str.insert(i, replace); + // jump to next position after insert + i += size_of_replace; + } + + return ret_str; } /**
M src/FbTk/StringUtil.hhsrc/FbTk/StringUtil.hh

@@ -41,6 +41,11 @@

/// @return extension of filename (ex: filename.txt will return txt) std::string findExtension(const std::string &filename); +/// @return copy of original with find_string replaced with "replace" +std::string replaceString(const std::string &original, + const char *find_string, + const char *replace); + /// returns string between character first and last int getStringBetween(std::string& out, const char *instr, char first, char last,