Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
split.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/split.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_SPLIT_HEADER
12 #define TLX_STRING_SPLIT_HEADER
13 
14 #include <string>
15 #include <vector>
16 
17 namespace tlx {
18 
19 //! \addtogroup tlx_string
20 //! \{
21 
22 /******************************************************************************/
23 // split() returning std::vector<std::string>
24 
25 /*!
26  * Split the given string at each separator character into distinct substrings.
27  * Multiple consecutive separators are considered individually and will result
28  * in empty split substrings.
29  *
30  * \param sep separator character
31  * \param str string to split
32  * \param limit maximum number of parts returned
33  * \return vector containing each split substring
34  */
35 std::vector<std::string> split(
36  char sep, const std::string& str,
37  std::string::size_type limit = std::string::npos);
38 
39 /*!
40  * Split the given string at each separator string into distinct substrings.
41  * Multiple consecutive separators are considered individually and will result
42  * in empty split substrings.
43  *
44  * \param sep separator string
45  * \param str string to split
46  * \param limit maximum number of parts returned
47  * \return vector containing each split substring
48  */
49 std::vector<std::string> split(
50  const char* sep, const std::string& str,
51  std::string::size_type limit = std::string::npos);
52 
53 /*!
54  * Split the given string at each separator string into distinct substrings.
55  * Multiple consecutive separators are considered individually and will result
56  * in empty split substrings.
57  *
58  * \param sep separator string
59  * \param str string to split
60  * \param limit maximum number of parts returned
61  * \return vector containing each split substring
62  */
63 std::vector<std::string> split(
64  const std::string& sep, const std::string& str,
65  std::string::size_type limit = std::string::npos);
66 
67 /******************************************************************************/
68 // split() returning std::vector<std::string> with minimum fields
69 
70 /*!
71  * Split the given string at each separator character into distinct substrings.
72  * Multiple consecutive separators are considered individually and will result
73  * in empty split substrings. Returns a vector of strings with at least
74  * min_fields and at most limit_fields, empty fields are added if needed.
75  *
76  * \param sep separator string
77  * \param str string to split
78  * \param min_fields minimum number of parts returned
79  * \param limit maximum number of parts returned
80  * \return vector containing each split substring
81  */
82 std::vector<std::string> split(
83  char sep, const std::string& str,
84  std::string::size_type min_fields, std::string::size_type limit);
85 
86 /*!
87  * Split the given string at each separator string into distinct substrings.
88  * Multiple consecutive separators are considered individually and will result
89  * in empty split substrings. Returns a vector of strings with at least
90  * min_fields and at most limit_fields, empty fields are added if needed.
91  *
92  * \param sep separator string
93  * \param str string to split
94  * \param min_fields minimum number of parts returned
95  * \param limit maximum number of parts returned
96  * \return vector containing each split substring
97  */
98 std::vector<std::string> split(
99  const char* sep, const std::string& str,
100  std::string::size_type min_fields, std::string::size_type limit);
101 
102 /*!
103  * Split the given string at each separator string into distinct substrings.
104  * Multiple consecutive separators are considered individually and will result
105  * in empty split substrings. Returns a vector of strings with at least
106  * min_fields and at most limit_fields, empty fields are added if needed.
107  *
108  * \param sep separator string
109  * \param str string to split
110  * \param min_fields minimum number of parts returned
111  * \param limit maximum number of parts returned
112  * \return vector containing each split substring
113  */
114 std::vector<std::string> split(
115  const std::string& sep, const std::string& str,
116  std::string::size_type min_fields, std::string::size_type limit);
117 
118 /******************************************************************************/
119 // split() into std::vector<std::string>
120 
121 /*!
122  * Split the given string at each separator character into distinct substrings.
123  * Multiple consecutive separators are considered individually and will result
124  * in empty split substrings.
125  *
126  * \param into destination std::vector
127  * \param sep separator character
128  * \param str string to split
129  * \param limit maximum number of parts returned
130  * \return vector containing each split substring
131  */
132 std::vector<std::string>& split(
133  std::vector<std::string>* into,
134  char sep, const std::string& str,
135  std::string::size_type limit = std::string::npos);
136 
137 /*!
138  * Split the given string at each separator string into distinct substrings.
139  * Multiple consecutive separators are considered individually and will result
140  * in empty split substrings.
141  *
142  * \param into destination std::vector
143  * \param sep separator string
144  * \param str string to split
145  * \param limit maximum number of parts returned
146  * \return vector containing each split substring
147  */
148 std::vector<std::string>& split(
149  std::vector<std::string>* into,
150  const char* sep, const std::string& str,
151  std::string::size_type limit = std::string::npos);
152 
153 /*!
154  * Split the given string at each separator string into distinct substrings.
155  * Multiple consecutive separators are considered individually and will result
156  * in empty split substrings.
157  *
158  * \param into destination std::vector
159  * \param sep separator string
160  * \param str string to split
161  * \param limit maximum number of parts returned
162  * \return vector containing each split substring
163  */
164 std::vector<std::string>& split(
165  std::vector<std::string>* into,
166  const std::string& sep, const std::string& str,
167  std::string::size_type limit = std::string::npos);
168 
169 /******************************************************************************/
170 // split() into std::vector<std::string> with minimum fields
171 
172 /*!
173  * Split the given string at each separator character into distinct substrings.
174  * Multiple consecutive separators are considered individually and will result
175  * in empty split substrings. Returns a vector of strings with at least
176  * min_fields and at most limit_fields, empty fields are added if needed.
177  *
178  * \param into destination std::vector
179  * \param sep separator character
180  * \param str string to split
181  * \param min_fields minimum number of parts returned
182  * \param limit maximum number of parts returned
183  * \return vector containing each split substring
184  */
185 std::vector<std::string>& split(
186  std::vector<std::string>* into,
187  char sep, const std::string& str,
188  std::string::size_type min_fields, std::string::size_type limit);
189 
190 /*!
191  * Split the given string at each separator string into distinct substrings.
192  * Multiple consecutive separators are considered individually and will result
193  * in empty split substrings. Returns a vector of strings with at least
194  * min_fields and at most limit_fields, empty fields are added if needed.
195  *
196  * \param into destination std::vector
197  * \param sep separator string
198  * \param str string to split
199  * \param min_fields minimum number of parts returned
200  * \param limit maximum number of parts returned
201  * \return vector containing each split substring
202  */
203 std::vector<std::string>& split(
204  std::vector<std::string>* into,
205  const char* sep, const std::string& str,
206  std::string::size_type min_fields, std::string::size_type limit);
207 
208 /*!
209  * Split the given string at each separator string into distinct substrings.
210  * Multiple consecutive separators are considered individually and will result
211  * in empty split substrings. Returns a vector of strings with at least
212  * min_fields and at most limit_fields, empty fields are added if needed.
213  *
214  * \param into destination std::vector
215  * \param sep separator string
216  * \param str string to split
217  * \param min_fields minimum number of parts returned
218  * \param limit maximum number of parts returned
219  * \return vector containing each split substring
220  */
221 std::vector<std::string>& split(
222  std::vector<std::string>* into,
223  const std::string& sep, const std::string& str,
224  std::string::size_type min_fields, std::string::size_type limit);
225 
226 //! \}
227 
228 } // namespace tlx
229 
230 #endif // !TLX_STRING_SPLIT_HEADER
231 
232 /******************************************************************************/
std::vector< std::string > split(char sep, const std::string &str, std::string::size_type limit)
Split the given string at each separator character into distinct substrings.
Definition: split.cpp:20
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220