Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template< typename char_type>
- static inline std::vector< std::basic_string< char_type > > basic_split(std::basic_string<char_type > string, const std::basic_string<char_type >& delim, bool keepEmpty = false) {
- std::vector < std::basic_string< char_type > > tokens;
- typename std::basic_string< char_type >::size_type pos;
- while (( pos = string.find(delim)) != string.npos) {
- if (pos) {
- std::basic_string<char_type> subString = string.substr(0, pos);
- if (subString.length() > 0 || keepEmpty)
- tokens.push_back(subString);
- } else if (keepEmpty) {
- tokens.push_back(std::basic_string<char_type >());
- }
- string.erase(0, pos + delim.length());
- }
- if (string.length()) {
- tokens.push_back(string);
- }
- return tokens;
- }
- static inline std::vector< std::string > split(std::string string, const std::string& delim, bool keepEmpty = false){
- return basic_split<char>(string, delim, keepEmpty);
- }
- static inline std::vector< std::wstring > split(std::wstring string, const std::wstring& delim, bool keepEmpty = false){
- return basic_split<wchar_t>(string, delim, keepEmpty);
- }
Add Comment
Please, Sign In to add comment