6#ifndef YARP_CONF_STRING_H
7#define YARP_CONF_STRING_H
25template <
typename ContainerT = std::vector<std::
string>>
29 using const_iterator_type =
typename string_type::const_iterator;
34 std::vector<string_type>
ret;
35 std::copy(std::regex_token_iterator<const_iterator_type>{s.begin(), s.end(), regex, -1},
36 std::regex_token_iterator<const_iterator_type>{},
37 std::back_inserter(
ret));
49template <
typename ContainerT = std::vector<std::
string>>
56 string_type sep_esc(separator.size()*2, char_type{
'\\'});
57 for (
size_t i = 0; i < s.size(); ++i) {
58 sep_esc[i*2 + 1] = separator[i];
61 return split<ContainerT>(s, std::basic_regex<char_type>{string_type{
"("} + sep_esc + string_type{
")|$"}});
72template <
typename ContainerT = std::vector<std::
string>>
78 return split<ContainerT>(s, std::basic_regex<char_type>{string_type{
"\\"} + string_type{separator} + string_type{
"|$"}});
91template <
typename ContainerT = std::vector<std::
string>>
93 typename ContainerT::const_iterator end,
98 using traits_type =
typename string_type::traits_type;
99 using allocator_type =
typename string_type::allocator_type;
105 std::basic_stringstream<char_type, traits_type, allocator_type> s;
106 std::copy(begin, end - 1, std::ostream_iterator<string_type, char_type, traits_type>(s, separator.c_str()));
121template <
typename ContainerT = std::vector<std::
string>>
123 typename ContainerT::const_iterator end,
ContainerT split(const typename ContainerT::value_type &s, std::basic_regex< typename ContainerT::value_type::value_type > regex)
Utility to split a string by a separator, into a vector of strings.
ContainerT::value_type join(typename ContainerT::const_iterator begin, typename ContainerT::const_iterator end, const typename ContainerT::value_type &separator=", ")
Utility to join the elements in a container to a single string separated by a separator.