aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/StringUtil.cc
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/FbTk/StringUtil.cc
parent4dec832b6bcef0503ac092a8cfdc370ab65f8f8f (diff)
downloadfluxbox_paul-a9f9e6d6eec6a42921e4446baef92eb5b2356d60.zip
fluxbox_paul-a9f9e6d6eec6a42921e4446baef92eb5b2356d60.tar.bz2
added replaceString
Diffstat (limited to 'src/FbTk/StringUtil.cc')
-rw-r--r--src/FbTk/StringUtil.cc26
1 files changed, 25 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