Thrill  0.1
replace.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/replace.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2007-2017 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_STRING_REPLACE_HEADER
12 #define TLX_STRING_REPLACE_HEADER
13 
14 #include <string>
15 
16 namespace tlx {
17 
18 //! \addtogroup tlx_string
19 //! \{
20 //! \name Search and Replace
21 //! \{
22 
23 /******************************************************************************/
24 // replace_first() in-place
25 
26 /*!
27  * Replace only the first occurrence of needle in str. The needle will be
28  * replaced with instead, if found. The replacement is done in the given string
29  * and a reference to the same is returned.
30  *
31  * \param str the string to process
32  * \param needle string to search for in str
33  * \param instead replace needle with instead
34  * \return reference to str
35  */
37  std::string* str, const std::string& needle, const std::string& instead);
38 
39 /*!
40  * Replace only the first occurrence of needle in str. The needle will be
41  * replaced with instead, if found. The replacement is done in the given string
42  * and a reference to the same is returned.
43  *
44  * \param str the string to process
45  * \param needle string to search for in str
46  * \param instead replace needle with instead
47  * \return reference to str
48  */
50  std::string* str, const std::string& needle, const char* instead);
51 
52 /*!
53  * Replace only the first occurrence of needle in str. The needle will be
54  * replaced with instead, if found. The replacement is done in the given string
55  * and a reference to the same is returned.
56  *
57  * \param str the string to process
58  * \param needle string to search for in str
59  * \param instead replace needle with instead
60  * \return reference to str
61  */
63  std::string* str, const char* needle, const std::string& instead);
64 
65 /*!
66  * Replace only the first occurrence of needle in str. The needle will be
67  * replaced with instead, if found. The replacement is done in the given string
68  * and a reference to the same is returned.
69  *
70  * \param str the string to process
71  * \param needle string to search for in str
72  * \param instead replace needle with instead
73  * \return reference to str
74  */
76  std::string* str, const char* needle, const char* instead);
77 
78 /*!
79  * Replace only the first occurrence of needle in str. The needle will be
80  * replaced with instead, if found. The replacement is done in the given string
81  * and a reference to the same is returned.
82  *
83  * \param str the string to process
84  * \param needle character to search for in str
85  * \param instead replace needle with instead
86  * \return reference to str
87  */
88 std::string& replace_first(std::string* str, char needle, char instead);
89 
90 /******************************************************************************/
91 // replace_first() copy
92 
93 /*!
94  * Replace only the first occurrence of needle in str. The needle will be
95  * replaced with instead, if found. Returns a copy of the string with the
96  * possible replacement.
97  *
98  * \param str the string to process
99  * \param needle string to search for in str
100  * \param instead replace needle with instead
101  * \return copy of string possibly with replacement
102  */
104  const std::string& str,
105  const std::string& needle, const std::string& instead);
106 
107 /*!
108  * Replace only the first occurrence of needle in str. The needle will be
109  * replaced with instead, if found. Returns a copy of the string with the
110  * possible replacement.
111  *
112  * \param str the string to process
113  * \param needle string to search for in str
114  * \param instead replace needle with instead
115  * \return copy of string possibly with replacement
116  */
118  const std::string& str, const std::string& needle, const char* instead);
119 
120 /*!
121  * Replace only the first occurrence of needle in str. The needle will be
122  * replaced with instead, if found. Returns a copy of the string with the
123  * possible replacement.
124  *
125  * \param str the string to process
126  * \param needle string to search for in str
127  * \param instead replace needle with instead
128  * \return copy of string possibly with replacement
129  */
131  const std::string& str, const char* needle, const std::string& instead);
132 
133 /*!
134  * Replace only the first occurrence of needle in str. The needle will be
135  * replaced with instead, if found. Returns a copy of the string with the
136  * possible replacement.
137  *
138  * \param str the string to process
139  * \param needle string to search for in str
140  * \param instead replace needle with instead
141  * \return copy of string possibly with replacement
142  */
144  const std::string& str, const char* needle, const char* instead);
145 
146 /*!
147  * Replace only the first occurrence of needle in str. The needle will be
148  * replaced with instead, if found. Returns a copy of the string with the
149  * possible replacement.
150  *
151  * \param str the string to process
152  * \param needle character to search for in str
153  * \param instead replace needle with instead
154  * \return copy of string possibly with replacement
155  */
156 std::string replace_first(const std::string& str, char needle, char instead);
157 
158 /******************************************************************************/
159 // replace_all() in-place
160 
161 /*!
162  * Replace all occurrences of needle in str. Each needle will be replaced with
163  * instead, if found. The replacement is done in the given string and a
164  * reference to the same is returned.
165  *
166  * \param str the string to process
167  * \param needle string to search for in str
168  * \param instead replace needle with instead
169  * \return reference to str
170  */
172  std::string* str, const std::string& needle, const std::string& instead);
173 
174 /*!
175  * Replace all occurrences of needle in str. Each needle will be replaced with
176  * instead, if found. The replacement is done in the given string and a
177  * reference to the same is returned.
178  *
179  * \param str the string to process
180  * \param needle string to search for in str
181  * \param instead replace needle with instead
182  * \return reference to str
183  */
185  std::string* str, const std::string& needle, const char* instead);
186 
187 /*!
188  * Replace all occurrences of needle in str. Each needle will be replaced with
189  * instead, if found. The replacement is done in the given string and a
190  * reference to the same is returned.
191  *
192  * \param str the string to process
193  * \param needle string to search for in str
194  * \param instead replace needle with instead
195  * \return reference to str
196  */
198  std::string* str, const char* needle, const std::string& instead);
199 
200 /*!
201  * Replace all occurrences of needle in str. Each needle will be replaced with
202  * instead, if found. The replacement is done in the given string and a
203  * reference to the same is returned.
204  *
205  * \param str the string to process
206  * \param needle string to search for in str
207  * \param instead replace needle with instead
208  * \return reference to str
209  */
211  std::string* str, const char* needle, const char* instead);
212 
213 /*!
214  * Replace all occurrences of needle in str. Each needle will be replaced with
215  * instead, if found. The replacement is done in the given string and a
216  * reference to the same is returned.
217  *
218  * \param str the string to process
219  * \param needle character to search for in str
220  * \param instead replace needle with instead
221  * \return reference to str
222  */
223 std::string& replace_all(std::string* str, char needle, char instead);
224 
225 /******************************************************************************/
226 // replace_all() copy
227 
228 /*!
229  * Replace all occurrences of needle in str. Each needle will be replaced with
230  * instead, if found. Returns a copy of the string with possible replacements.
231  *
232  * \param str the string to process
233  * \param needle string to search for in str
234  * \param instead replace needle with instead
235  * \return copy of string possibly with replacements
236  */
238  const std::string& str,
239  const std::string& needle, const std::string& instead);
240 
241 /*!
242  * Replace all occurrences of needle in str. Each needle will be replaced with
243  * instead, if found. Returns a copy of the string with possible replacements.
244  *
245  * \param str the string to process
246  * \param needle string to search for in str
247  * \param instead replace needle with instead
248  * \return copy of string possibly with replacements
249  */
251  const std::string& str, const std::string& needle, const char* instead);
252 
253 /*!
254  * Replace all occurrences of needle in str. Each needle will be replaced with
255  * instead, if found. Returns a copy of the string with possible replacements.
256  *
257  * \param str the string to process
258  * \param needle string to search for in str
259  * \param instead replace needle with instead
260  * \return copy of string possibly with replacements
261  */
263  const std::string& str, const char* needle, const std::string& instead);
264 
265 /*!
266  * Replace all occurrences of needle in str. Each needle will be replaced with
267  * instead, if found. Returns a copy of the string with possible replacements.
268  *
269  * \param str the string to process
270  * \param needle string to search for in str
271  * \param instead replace needle with instead
272  * \return copy of string possibly with replacements
273  */
275  const std::string& str, const char* needle, const char* instead);
276 
277 /*!
278  * Replace all occurrences of needle in str. Each needle will be replaced with
279  * instead, if found. Returns a copy of the string with possible replacements.
280  *
281  * \param str the string to process
282  * \param needle character to search for in str
283  * \param instead replace needle with instead
284  * \return copy of string possibly with replacements
285  */
286 std::string replace_all(const std::string& str, char needle, char instead);
287 
288 //! \}
289 //! \}
290 
291 } // namespace tlx
292 
293 #endif // !TLX_STRING_REPLACE_HEADER
294 
295 /******************************************************************************/
std::string & replace_all(std::string *str, const std::string &needle, const std::string &instead)
Replace all occurrences of needle in str.
Definition: replace.cpp:141
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
std::string & replace_first(std::string *str, const std::string &needle, const std::string &instead)
Replace only the first occurrence of needle in str.
Definition: replace.cpp:21