22 std::string* str,
const std::string& needle,
const std::string& instead) {
24 std::string::size_type firstpos = str->find(needle);
26 if (firstpos != std::string::npos)
27 str->replace(firstpos, needle.size(), instead);
33 std::string* str,
const std::string& needle,
const char* instead) {
35 std::string::size_type firstpos = str->find(needle);
37 if (firstpos != std::string::npos)
38 str->replace(firstpos, needle.size(), instead);
44 std::string* str,
const char* needle,
const std::string& instead) {
46 std::string::size_type firstpos = str->find(needle);
48 if (firstpos != std::string::npos)
49 str->replace(firstpos, strlen(needle), instead);
55 std::string* str,
const char* needle,
const char* instead) {
57 std::string::size_type firstpos = str->find(needle);
59 if (firstpos != std::string::npos)
60 str->replace(firstpos, strlen(needle), instead);
65 std::string&
replace_first(std::string* str,
char needle,
char instead) {
67 std::string::size_type firstpos = str->find(needle);
69 if (firstpos != std::string::npos)
70 (*str)[firstpos] = instead;
79 const std::string& str,
80 const std::string& needle,
const std::string& instead) {
82 std::string newstr = str;
83 std::string::size_type firstpos = newstr.find(needle);
85 if (firstpos != std::string::npos)
86 newstr.replace(firstpos, needle.size(), instead);
92 const std::string& str,
const std::string& needle,
const char* instead) {
94 std::string newstr = str;
95 std::string::size_type firstpos = newstr.find(needle);
97 if (firstpos != std::string::npos)
98 newstr.replace(firstpos, needle.size(), instead);
104 const std::string& str,
const char* needle,
const std::string& instead) {
106 std::string newstr = str;
107 std::string::size_type firstpos = newstr.find(needle);
109 if (firstpos != std::string::npos)
110 newstr.replace(firstpos, strlen(needle), instead);
116 const std::string& str,
const char* needle,
const char* instead) {
118 std::string newstr = str;
119 std::string::size_type firstpos = newstr.find(needle);
121 if (firstpos != std::string::npos)
122 newstr.replace(firstpos, strlen(needle), instead);
127 std::string
replace_first(
const std::string& str,
char needle,
char instead) {
129 std::string newstr = str;
130 std::string::size_type firstpos = newstr.find(needle);
132 if (firstpos != std::string::npos)
133 newstr[firstpos] = instead;
142 std::string* str,
const std::string& needle,
const std::string& instead) {
144 std::string::size_type lastpos = 0, thispos;
146 while ((thispos = str->find(needle, lastpos)) != std::string::npos)
148 str->replace(thispos, needle.size(), instead);
149 lastpos = thispos + instead.size();
155 std::string* str,
const std::string& needle,
const char* instead) {
157 std::string::size_type lastpos = 0, thispos;
158 size_t instead_size = strlen(instead);
160 while ((thispos = str->find(needle, lastpos)) != std::string::npos)
162 str->replace(thispos, needle.size(), instead);
163 lastpos = thispos + instead_size;
169 std::string* str,
const char* needle,
const std::string& instead) {
171 std::string::size_type lastpos = 0, thispos;
172 size_t needle_size = strlen(needle);
174 while ((thispos = str->find(needle, lastpos)) != std::string::npos)
176 str->replace(thispos, needle_size, instead);
177 lastpos = thispos + instead.size();
183 std::string* str,
const char* needle,
const char* instead) {
185 std::string::size_type lastpos = 0, thispos;
186 size_t needle_size = strlen(needle);
187 size_t instead_size = strlen(instead);
189 while ((thispos = str->find(needle, lastpos)) != std::string::npos)
191 str->replace(thispos, needle_size, instead);
192 lastpos = thispos + instead_size;
197 std::string&
replace_all(std::string* str,
char needle,
char instead) {
199 std::string::size_type lastpos = 0, thispos;
201 while ((thispos = str->find(needle, lastpos)) != std::string::npos)
203 (*str)[thispos] = instead;
204 lastpos = thispos + 1;
213 const std::string& str,
214 const std::string& needle,
const std::string& instead) {
216 std::string newstr = str;
217 std::string::size_type lastpos = 0, thispos;
219 while ((thispos = newstr.find(needle, lastpos)) != std::string::npos)
221 newstr.replace(thispos, needle.size(), instead);
222 lastpos = thispos + instead.size();
228 const std::string& str,
const std::string& needle,
const char* instead) {
230 std::string newstr = str;
231 std::string::size_type lastpos = 0, thispos;
232 size_t instead_size = strlen(instead);
234 while ((thispos = newstr.find(needle, lastpos)) != std::string::npos)
236 newstr.replace(thispos, needle.size(), instead);
237 lastpos = thispos + instead_size;
243 const std::string& str,
const char* needle,
const std::string& instead) {
245 std::string newstr = str;
246 std::string::size_type lastpos = 0, thispos;
247 size_t needle_size = strlen(needle);
249 while ((thispos = newstr.find(needle, lastpos)) != std::string::npos)
251 newstr.replace(thispos, needle_size, instead);
252 lastpos = thispos + instead.size();
258 const std::string& str,
const char* needle,
const char* instead) {
260 std::string newstr = str;
261 std::string::size_type lastpos = 0, thispos;
262 size_t needle_size = strlen(needle);
263 size_t instead_size = strlen(instead);
265 while ((thispos = newstr.find(needle, lastpos)) != std::string::npos)
267 newstr.replace(thispos, needle_size, instead);
268 lastpos = thispos + instead_size;
273 std::string
replace_all(
const std::string& str,
char needle,
char instead) {
275 std::string newstr = str;
276 std::string::size_type lastpos = 0, thispos;
278 while ((thispos = newstr.find(needle, lastpos)) != std::string::npos)
280 newstr[thispos] = instead;
281 lastpos = thispos + 1;
std::string & replace_all(std::string *str, const std::string &needle, const std::string &instead)
Replace all occurrences of needle in str.
std::string & replace_first(std::string *str, const std::string &needle, const std::string &instead)
Replace only the first occurrence of needle in str.