9 #ifndef JabberC_utilities_h
10 #define JabberC_utilities_h
16 inline std::vector<std::string> split(
const std::string & text,
char delim )
18 std::vector<std::string> tokens;
19 std::istringstream iss( text );
22 while ( std::getline( iss, token, delim ) )
24 tokens.push_back( token );
32 std::basic_string<_T> & emptyString()
34 static std::basic_string<_T> empty;
40 class basic_token_iterator :
public std::iterator<std::forward_iterator_tag, std::basic_string<_T> >
43 const std::basic_string<_T> & strInput;
44 const _T * szDelimiters;
45 typename std::basic_string<_T>::size_type bot, eot;
48 basic_token_iterator(
const std::basic_string<_T> & strInput,
const _T * szDelimiters ) :
50 szDelimiters( szDelimiters ),
51 bot( strInput.find_first_not_of( szDelimiters ) ),
52 eot( strInput.find_first_of( szDelimiters, bot ) )
55 basic_token_iterator(
void ) :
56 strInput(emptyString<_T>()),
62 std::string operator* ()
const
64 if ( eot != std::basic_string<_T>::npos )
66 return strInput.substr( bot, eot-bot );
68 else if ( bot != std::basic_string<_T>::npos )
70 return strInput.substr( bot );
77 basic_token_iterator<_T> & operator++ ()
79 if ( eot != std::basic_string<_T>::npos )
81 bot = strInput.find_first_not_of( szDelimiters, eot );
82 eot = strInput.find_first_of( szDelimiters, bot );
84 else if ( bot != std::basic_string<_T>::npos )
86 bot = std::basic_string<_T>::npos;
91 basic_token_iterator<_T> operator++ (
int)
93 basic_token_iterator<_T> save = *
this;
98 bool operator== (
const basic_token_iterator<_T> & rhs )
const
100 if ( &strInput == &rhs.strInput && bot == rhs.bot && eot == rhs.eot )
104 else if ( strInput.empty() && rhs.strInput.empty() )
108 else if ( strInput.empty() && rhs.bot == std::basic_string<_T>::npos && rhs.eot == std::basic_string<_T>::npos )
112 else if ( rhs.strInput.empty() && bot == std::basic_string<_T>::npos && eot == std::basic_string<_T>::npos )
121 bool operator!= (
const basic_token_iterator<_T> & rhs )
const
123 return !(*
this == rhs);
128 typedef basic_token_iterator<char> token_iterator;
129 typedef basic_token_iterator<wchar_t> wtoken_iterator;