Showing the changes to src/core/util_string.cpp (1 of 4 files). Show all
Unified · Split
| @@ -828,3 +828,50 @@ std::string timestamp_formatted() · 827 unmodified lines | |||
| 828 | // return the formatted timestamp | 828 | // return the formatted timestamp |
| 829 | return datetime_buf; | 829 | return datetime_buf; |
| 830 | } | 830 | } |
| 831 | |||
| 832 | |||
| 833 | |||
| 834 | static t_CKBOOL str_contains( const string & s, char c ) | ||
| 835 | { return s.find( c ) != string::npos; } | ||
| 836 | |||
| 837 | //----------------------------------------------------------------------------- | ||
| 838 | // name: tokenize() | 1.5.0.4 (ge) added | ||
| 839 | // desc: tokenize a string into a vector of strings, by delimiters | ||
| 840 | //----------------------------------------------------------------------------- | ||
| 841 | void tokenize( const std::string & str, std::vector<string> & tokens, const std::string & delimiters ) | ||
| 842 | { | ||
| 843 | // string length | ||
| 844 | t_CKINT len = str.length(); | ||
| 845 | // clear vector | ||
| 846 | tokens.clear(); | ||
| 847 | // token start index | ||
| 848 | t_CKINT start = 0; | ||
| 849 | |||
| 850 | // scan through str | ||
| 851 | for( t_CKINT i = 0; i < len; i++ ) | ||
| 852 | { | ||
| 853 | // check for delimiters | ||
| 854 | if( str_contains( delimiters, str[i] ) ) | ||
| 855 | { | ||
| 856 | // substr len | ||
| 857 | t_CKINT slen = i-start; | ||
| 858 | // check | ||
| 859 | if( len > 0 ) | ||
| 860 | { | ||
| 861 | // push back the substr | ||
| 862 | tokens.push_back( str.substr( start, slen ) ); | ||
| 863 | } | ||
| 864 | // update the start pos | ||
| 865 | start = i+1; | ||
| 866 | } | ||
| 867 | } | ||
| 868 | |||
| 869 | // get the remainder | ||
| 870 | t_CKINT slen = len-start; | ||
| 871 | // check | ||
| 872 | if( len > 0 ) | ||
| 873 | { | ||
| 874 | // push back the substr | ||
| 875 | tokens.push_back( str.substr( start, slen ) ); | ||
| 876 | } | ||
| 877 | } | ||