aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/src/mpt/parse/split.hpp
blob: 9166ad7efe3f6c0abf15edfc0c0092b80859ece4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */

#ifndef MPT_PARSE_SPLIT_HPP
#define MPT_PARSE_SPLIT_HPP



#include "mpt/base/namespace.hpp"
#include "mpt/parse/parse.hpp"
#include "mpt/string/utility.hpp"

#include <vector>

#include <cstddef>



namespace mpt {
inline namespace MPT_INLINE_NS {



template <typename T, typename Tstring>
std::vector<T> split_parse(const Tstring & str, const Tstring & sep = Tstring(1, char_constants<typename Tstring::value_type>::comma)) {
	std::vector<T> vals;
	std::size_t pos = 0;
	while (str.find(sep, pos) != std::string::npos) {
		vals.push_back(mpt::ConvertStringTo<T>(str.substr(pos, str.find(sep, pos) - pos)));
		pos = str.find(sep, pos) + sep.length();
	}
	if (!vals.empty() || (str.substr(pos).length() > 0)) {
		vals.push_back(mpt::ConvertStringTo<T>(str.substr(pos)));
	}
	return vals;
}



} // namespace MPT_INLINE_NS
} // namespace mpt



#endif // MPT_PARSE_SPLIT_HPP