6 #ifndef YARP_CONF_STRING_H
7 #define YARP_CONF_STRING_H
26 template <
typename ContainerT = std::vector<std::
string>>
30 using const_iterator_type =
typename string_type::const_iterator;
35 std::vector<string_type>
ret;
36 std::copy(std::regex_token_iterator<const_iterator_type>{s.begin(), s.end(), regex, -1},
37 std::regex_token_iterator<const_iterator_type>{},
38 std::back_inserter(
ret));
50 template <
typename ContainerT = std::vector<std::
string>>
57 string_type sep_esc(separator.size()*2, char_type{
'\\'});
58 for (
size_t i = 0; i < s.size(); ++i) {
59 sep_esc[i*2 + 1] = separator[i];
62 return split<ContainerT>(s, std::basic_regex<char_type>{string_type{
"("} + sep_esc + string_type{
")|$"}});
73 template <
typename ContainerT = std::vector<std::
string>>
79 return split<ContainerT>(s, std::basic_regex<char_type>{string_type{
"\\"} + string_type{separator} + string_type{
"|$"}});
92 template <
typename ContainerT = std::vector<std::
string>>
94 typename ContainerT::const_iterator end,
99 using traits_type =
typename string_type::traits_type;
100 using allocator_type =
typename string_type::allocator_type;
106 std::basic_stringstream<char_type, traits_type, allocator_type> s;
107 std::copy(begin, end - 1, std::ostream_iterator<string_type, char_type, traits_type>(s, separator.c_str()));
122 template <
typename ContainerT = std::vector<std::
string>>
124 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.
The main, catch-all namespace for YARP.