aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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,