nds2-client - ClientDeveloper  0.16.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nds_str_utility.hh
Go to the documentation of this file.
1 #ifndef NDS_DETAIL_STR_UTIL_HH
2 #define NDS_DETAIL_STR_UTIL_HH
3 
4 #include <algorithm>
5 #include <string>
6 #include <vector>
7 
8 namespace NDS
9 {
10  namespace detail
11  {
12  template < typename iter >
13  void
14  split( iter first,
15  iter last,
16  char delim,
17  std::vector< std::string >& dest )
18  {
19  std::vector< std::string > results;
20  if ( first == last )
21  {
22  return;
23  }
24  iter cur = first;
25  iter prev = first;
26  cur = std::find( prev, last, delim );
27  while ( cur != last )
28  {
29  // prev -> cur = a segment
30  results.push_back( std::string( prev, cur ) );
31 
32  prev = cur;
33  ++prev;
34  cur = std::find( prev, last, delim );
35  }
36  // prev -> last = last segment
37  results.push_back( std::string( prev, cur ) );
38 
39  dest.swap( results );
40  }
41 
42  inline void
43  split( const std::string& inp,
44  char delim,
45  std::vector< std::string >& dest )
46  {
47  split( inp.begin( ), inp.end( ), delim, dest );
48  }
49 
50  inline std::vector< std::string >
51  split( const std::string& inp, char delim )
52  {
53  std::vector< std::string > retval;
54  split( inp, delim, retval );
55  return retval;
56  }
57  }
58 }
59 
60 #endif // NDS_DETAIL_STR_UTIL_HH
void split(iter first, iter last, char delim, std::vector< std::string > &dest)
Definition: nds_str_utility.hh:14