Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
21 /******************************************************************************/
22 // replace_first() in-place
23 
24 /*!
25  * Replace only the first occurrence of needle in str. The needle will be
26  * replaced with instead, if found. The replacement is done in the given string
27  * and a reference to the same is returned.
28  *
29  * \param str the string to process
30  * \param needle string to search for in str
31  * \param instead replace needle with instead
32  * \return reference to str
33  */
35  std::string* str, const std::string& needle, const std::string& instead);
36 
37 /*!
38  * Replace only the first occurrence of needle in str. The needle will be
39  * replaced with instead, if found. The replacement is done in the given string
40  * and a reference to the same is returned.
41  *
42  * \param str the string to process
43  * \param needle string to search for in str
44  * \param instead replace needle with instead
45  * \return reference to str
46  */
48  std::string* str, const std::string& needle, const char* instead);
49 
50 /*!
51  * Replace only the first occurrence of needle in str. The needle will be
52  * replaced with instead, if found. The replacement is done in the given string
53  * and a reference to the same is returned.
54  *
55  * \param str the string to process
56  * \param needle string to search for in str
57  * \param instead replace needle with instead
58  * \return reference to str
59  */
61  std::string* str, const char* needle, const std::string& instead);
62 
63 /*!
64  * Replace only the first occurrence of needle in str. The needle will be
65  * replaced with instead, if found. The replacement is done in the given string
66  * and a reference to the same is returned.
67  *
68  * \param str the string to process
69  * \param needle string to search for in str
70  * \param instead replace needle with instead
71  * \return reference to str
72  */
74  std::string* str, const char* needle, const char* instead);
75 
76 /*!
77  * Replace only the first occurrence of needle in str. The needle will be
78  * replaced with instead, if found. The replacement is done in the given string
79  * and a reference to the same is returned.
80  *
81  * \param str the string to process
82  * \param needle character to search for in str
83  * \param instead replace needle with instead
84  * \return reference to str
85  */
86 std::string& replace_first(std::string* str, char needle, char instead);
87 
88 /******************************************************************************/
89 // replace_first() copy
90 
91 /*!
92  * Replace only the first occurrence of needle in str. The needle will be
93  * replaced with instead, if found. Returns a copy of the string with the
94  * possible replacement.
95  *
96  * \param str the string to process
97  * \param needle string to search for in str
98  * \param instead replace needle with instead
99  * \return copy of string possibly with replacement
100  */
102  const std::string& str,
103  const std::string& needle, const std::string& instead);
104 
105 /*!
106  * Replace only the first occurrence of needle in str. The needle will be
107  * replaced with instead, if found. Returns a copy of the string with the
108  * possible replacement.
109  *
110  * \param str the string to process
111  * \param needle string to search for in str
112  * \param instead replace needle with instead
113  * \return copy of string possibly with replacement
114  */
116  const std::string& str, const std::string& needle, const char* instead);
117 
118 /*!
119  * Replace only the first occurrence of needle in str. The needle will be
120  * replaced with instead, if found. Returns a copy of the string with the
121  * possible replacement.
122  *
123  * \param str the string to process
124  * \param needle string to search for in str
125  * \param instead replace needle with instead
126  * \return copy of string possibly with replacement
127  */
129  const std::string& str, const char* needle, const std::string& instead);
130 
131 /*!
132  * Replace only the first occurrence of needle in str. The needle will be
133  * replaced with instead, if found. Returns a copy of the string with the
134  * possible replacement.
135  *
136  * \param str the string to process
137  * \param needle string to search for in str
138  * \param instead replace needle with instead
139  * \return copy of string possibly with replacement
140  */
142  const std::string& str, const char* needle, const char* instead);
143 
144 /*!
145  * Replace only the first occurrence of needle in str. The needle will be
146  * replaced with instead, if found. Returns a copy of the string with the
147  * possible replacement.
148  *
149  * \param str the string to process
150  * \param needle character to search for in str
151  * \param instead replace needle with instead
152  * \return copy of string possibly with replacement
153  */
154 std::string replace_first(const std::string& str, char needle, char instead);
155 
156 /******************************************************************************/
157 // replace_all() in-place
158 
159 /*!
160  * Replace all occurrences of needle in str. Each needle will be replaced with
161  * instead, if found. The replacement is done in the given string and a
162  * reference to the same is returned.
163  *
164  * \param str the string to process
165  * \param needle string to search for in str
166  * \param instead replace needle with instead
167  * \return reference to str
168  */
170  std::string* str, const std::string& needle, const std::string& instead);
171 
172 /*!
173  * Replace all occurrences of needle in str. Each needle will be replaced with
174  * instead, if found. The replacement is done in the given string and a
175  * reference to the same is returned.
176  *
177  * \param str the string to process
178  * \param needle string to search for in str
179  * \param instead replace needle with instead
180  * \return reference to str
181  */
183  std::string* str, const std::string& needle, const char* instead);
184 
185 /*!
186  * Replace all occurrences of needle in str. Each needle will be replaced with
187  * instead, if found. The replacement is done in the given string and a
188  * reference to the same is returned.
189  *
190  * \param str the string to process
191  * \param needle string to search for in str
192  * \param instead replace needle with instead
193  * \return reference to str
194  */
196  std::string* str, const char* needle, const std::string& instead);
197 
198 /*!
199  * Replace all occurrences of needle in str. Each needle will be replaced with
200  * instead, if found. The replacement is done in the given string and a
201  * reference to the same is returned.
202  *
203  * \param str the string to process
204  * \param needle string to search for in str
205  * \param instead replace needle with instead
206  * \return reference to str
207  */
209  std::string* str, const char* needle, const char* instead);
210 
211 /*!
212  * Replace all occurrences of needle in str. Each needle will be replaced with
213  * instead, if found. The replacement is done in the given string and a
214  * reference to the same is returned.
215  *
216  * \param str the string to process
217  * \param needle character to search for in str
218  * \param instead replace needle with instead
219  * \return reference to str
220  */
221 std::string& replace_all(std::string* str, char needle, char instead);
222 
223 /******************************************************************************/
224 // replace_all() copy
225 
226 /*!
227  * Replace all occurrences of needle in str. Each needle will be replaced with
228  * instead, if found. Returns a copy of the string with possible replacements.
229  *
230  * \param str the string to process
231  * \param needle string to search for in str
232  * \param instead replace needle with instead
233  * \return copy of string possibly with replacements
234  */
236  const std::string& str,
237  const std::string& needle, const std::string& instead);
238 
239 /*!
240  * Replace all occurrences of needle in str. Each needle will be replaced with
241  * instead, if found. Returns a copy of the string with possible replacements.
242  *
243  * \param str the string to process
244  * \param needle string to search for in str
245  * \param instead replace needle with instead
246  * \return copy of string possibly with replacements
247  */
249  const std::string& str, const std::string& needle, const char* instead);
250 
251 /*!
252  * Replace all occurrences of needle in str. Each needle will be replaced with
253  * instead, if found. Returns a copy of the string with possible replacements.
254  *
255  * \param str the string to process
256  * \param needle string to search for in str
257  * \param instead replace needle with instead
258  * \return copy of string possibly with replacements
259  */
261  const std::string& str, const char* needle, const std::string& instead);
262 
263 /*!
264  * Replace all occurrences of needle in str. Each needle will be replaced with
265  * instead, if found. Returns a copy of the string with possible replacements.
266  *
267  * \param str the string to process
268  * \param needle string to search for in str
269  * \param instead replace needle with instead
270  * \return copy of string possibly with replacements
271  */
273  const std::string& str, const char* needle, const char* instead);
274 
275 /*!
276  * Replace all occurrences of needle in str. Each needle will be replaced with
277  * instead, if found. Returns a copy of the string with possible replacements.
278  *
279  * \param str the string to process
280  * \param needle character to search for in str
281  * \param instead replace needle with instead
282  * \return copy of string possibly with replacements
283  */
284 std::string replace_all(const std::string& str, char needle, char instead);
285 
286 //! \}
287 
288 } // namespace tlx
289 
290 #endif // !TLX_STRING_REPLACE_HEADER
291 
292 /******************************************************************************/
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