#include <OSGBaseFunctions.h>
Public Member Functions | |
| string_token_iterator () | |
| string_token_iterator (const std::string &str_, const char *separator_=" ") | |
| string_token_iterator (const string_token_iterator &rhs) | |
| string_token_iterator & | operator++ () |
| string_token_iterator | operator++ (int) |
| std::string | operator * () const |
| bool | operator== (const string_token_iterator &rhs) const |
| bool | operator!= (const string_token_iterator &rhs) const |
Private Member Functions | |
| void | find_next (void) |
Private Attributes | |
| const char * | _separator |
| const std::string * | _str |
| std::string::size_type | _start |
| std::string::size_type | _end |
Definition at line 578 of file OSGBaseFunctions.h.
| string_token_iterator::string_token_iterator | ( | ) |
Default constructs a new iterator that has no string and no separators. This constructor exists only to make this type default constructible, but since there is no way to later set the string or the separators it's quite useless.
Definition at line 209 of file OSGBaseFunctions.cpp.
00209 : 00210 _separator(0), 00211 _str (0), 00212 _start (0), 00213 _end (0) 00214 { 00215 }
| string_token_iterator::string_token_iterator | ( | const std::string & | str, | |
| const char * | separator = " " | |||
| ) |
Creates a new iterator that operates on the string str and splits it at the separators given in the C string separator.
| [in] | str | String to iterator over. |
| [in] | separator | Characters at which the string is split. |
Definition at line 226 of file OSGBaseFunctions.cpp.
References find_next().
00227 : 00228 _separator( separator), 00229 _str (&str ), 00230 _start ( 0 ), 00231 _end ( 0 ) 00232 { 00233 find_next(); 00234 }
| string_token_iterator::string_token_iterator | ( | const string_token_iterator & | rhs | ) |
Creates a new iterator with the internal state of rhs, i.e. the new iterator operates on the same string with the same separators as rhs and operator*() will return the same substring on its next call for both iterators.
| [in] | rhs | Iterator to copy. |
Definition at line 246 of file OSGBaseFunctions.cpp.
00247 : 00248 00249 _separator(rhs._separator), 00250 _str (rhs._str ), 00251 _start (rhs._start ), 00252 _end (rhs._end ) 00253 { 00254 }
| string_token_iterator & string_token_iterator::operator++ | ( | ) |
Advances to the next token.
Definition at line 260 of file OSGBaseFunctions.cpp.
References find_next().
00261 { 00262 find_next(); 00263 00264 return *this; 00265 }
| string_token_iterator string_token_iterator::operator++ | ( | int | ) |
Advances to the next token and returns a copy of this from before it was advanced.
Definition at line 272 of file OSGBaseFunctions.cpp.
00273 { 00274 string_token_iterator temp(*this); 00275 00276 ++(*this); 00277 00278 return temp; 00279 }
| std::string string_token_iterator::operator * | ( | ) | const |
Returns the next token from the string or an empty string if there are no further tokens.
Definition at line 286 of file OSGBaseFunctions.cpp.
References _end, _start, and _str.
00287 { 00288 std::string returnValue; 00289 00290 if(_end == std::string::npos) 00291 { 00292 returnValue = _str->substr(_start); 00293 } 00294 else 00295 { 00296 returnValue = _str->substr(_start, _end - _start); 00297 } 00298 00299 return returnValue; 00300 }
| bool string_token_iterator::operator== | ( | const string_token_iterator & | rhs | ) | const |
Compares this to another string_token_iterator rhs for equality. They are considered equal if they operator on the same string and will return the same token on the next call to operator*().
| [in] | rhs | Iterator to compare this with. |
true if the iterators are equal, false otherwise. Definition at line 309 of file OSGBaseFunctions.cpp.
References _end, _start, and _str.
| bool string_token_iterator::operator!= | ( | const string_token_iterator & | rhs | ) | const |
Compares this to another string_token_iterator rhs for inequality. They are considered not equal, if a comparison for equality would return false.
| [in] | rhs | Iterator to compare this with. |
true if the iterators are not equal, false otherwise. Definition at line 321 of file OSGBaseFunctions.cpp.
| void string_token_iterator::find_next | ( | void | ) | [private] |
Advances the internal state to the next token.
Definition at line 328 of file OSGBaseFunctions.cpp.
References _end, _separator, _start, and _str.
Referenced by operator++(), and string_token_iterator().
00329 { 00330 _start = _str->find_first_not_of(_separator, _end); 00331 00332 // Apparently some STL implementations don't do npos !?! 00333 if(_start == std::string::npos || _start >= _str->length()) 00334 { 00335 _start = _end = 0; 00336 _str = 0; 00337 return; 00338 } 00339 00340 _end = _str->find_first_of(_separator, _start); 00341 }
const char* OSG::string_token_iterator::_separator [private] |
const std::string* OSG::string_token_iterator::_str [private] |
Definition at line 608 of file OSGBaseFunctions.h.
Referenced by find_next(), operator *(), and operator==().
std::string::size_type OSG::string_token_iterator::_start [private] |
Definition at line 609 of file OSGBaseFunctions.h.
Referenced by find_next(), operator *(), and operator==().
std::string::size_type OSG::string_token_iterator::_end [private] |
Definition at line 610 of file OSGBaseFunctions.h.
Referenced by find_next(), operator *(), and operator==().