summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2005-10-20 14:48:53 (GMT)
committerfluxgen <fluxgen>2005-10-20 14:48:53 (GMT)
commita9f9e6d6eec6a42921e4446baef92eb5b2356d60 (patch)
tree98ae1484d46074cf61469284acad18f5f90350f4 /src
parent4dec832b6bcef0503ac092a8cfdc370ab65f8f8f (diff)
downloadfluxbox_lack-a9f9e6d6eec6a42921e4446baef92eb5b2356d60.zip
fluxbox_lack-a9f9e6d6eec6a42921e4446baef92eb5b2356d60.tar.bz2
added replaceString
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/StringUtil.cc26
-rw-r--r--src/FbTk/StringUtil.hh5
2 files changed, 30 insertions, 1 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index c3580ec..3066615 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -23,7 +23,7 @@
23 23
24#include "StringUtil.hh" 24#include "StringUtil.hh"
25 25
26#include <string> 26
27#ifdef HAVE_CSTDIO 27#ifdef HAVE_CSTDIO
28 #include <cstdio> 28 #include <cstdio>
29#else 29#else
@@ -44,8 +44,11 @@
44#else 44#else
45 #include <assert.h> 45 #include <assert.h>
46#endif 46#endif
47
48
47#include <memory> 49#include <memory>
48#include <algorithm> 50#include <algorithm>
51#include <string>
49 52
50using namespace std; 53using namespace std;
51 54
@@ -116,6 +119,27 @@ string findExtension(const std::string &filename) {
116 return filename.substr(start_pos + 1); 119 return filename.substr(start_pos + 1);
117} 120}
118 121
122string replaceString(const std::string &original,
123 const char *findthis,
124 const char *replace) {
125 int i=0;
126 const int size_of_replace = strlen(replace);
127 const int size_of_find = strlen(findthis);
128 string ret_str(original);
129 while (i < ret_str.size()) {
130 i = ret_str.find(findthis, i);
131 if (i == std::string::npos)
132 break;
133 // erase old string and insert replacement
134 ret_str.erase(i, size_of_find);
135 ret_str.insert(i, replace);
136 // jump to next position after insert
137 i += size_of_replace;
138 }
139
140 return ret_str;
141}
142
119/** 143/**
120 Parses a string between "first" and "last" characters 144 Parses a string between "first" and "last" characters
121 and ignoring ok_chars as whitespaces. The value is 145 and ignoring ok_chars as whitespaces. The value is
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index 3112a9d..b79b46a 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -41,6 +41,11 @@ std::string expandFilename(const std::string &filename);
41/// @return extension of filename (ex: filename.txt will return txt) 41/// @return extension of filename (ex: filename.txt will return txt)
42std::string findExtension(const std::string &filename); 42std::string findExtension(const std::string &filename);
43 43
44/// @return copy of original with find_string replaced with "replace"
45std::string replaceString(const std::string &original,
46 const char *find_string,
47 const char *replace);
48
44/// returns string between character first and last 49/// returns string between character first and last
45int getStringBetween(std::string& out, const char *instr, 50int getStringBetween(std::string& out, const char *instr,
46 char first, char last, 51 char first, char last,