File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -203,3 +203,21 @@ std::list<std::string> splitString(const std::string& str, char sep)
203
203
l.push_back (std::move (p));
204
204
return l;
205
205
}
206
+
207
+ std::vector<std::string> splitStringVector (const std::string& str, char sep)
208
+ {
209
+ if (std::strchr (str.c_str (), sep) == nullptr )
210
+ return {str};
211
+
212
+ std::vector<std::string> l;
213
+ std::string p (str);
214
+ for (;;) {
215
+ const std::string::size_type pos = p.find (sep);
216
+ if (pos == std::string::npos)
217
+ break ;
218
+ l.push_back (p.substr (0 ,pos));
219
+ p = p.substr (pos+1 );
220
+ }
221
+ l.push_back (std::move (p));
222
+ return l;
223
+ }
Original file line number Diff line number Diff line change @@ -405,6 +405,14 @@ static inline T* empty_if_null(T* p)
405
405
*/
406
406
CPPCHECKLIB std::list<std::string> splitString (const std::string& str, char sep);
407
407
408
+ /* *
409
+ * Split string by given sperator.
410
+ * @param str The string to split
411
+ * @param sep The seperator
412
+ * @return The vector of seperate strings (including empty ones). The whole input string if no seperator found.
413
+ */
414
+ CPPCHECKLIB std::vector<std::string> splitStringVector (const std::string& str, char sep);
415
+
408
416
namespace utils {
409
417
template <class T >
410
418
constexpr typename std::add_const<T>::type & as_const (T& t) noexcept
You can’t perform that action at this time.
0 commit comments