Sierra Toolkit Version of the Day
tokenize.cpp
00001 #include "tokenize.hpp"
00002 
00003 void stk::util::tokenize(const std::string& str, const std::string& separators,
00004        std::vector<std::string>& tokens)
00005 {
00006   std::string curr_token = "";
00007   for (size_t i = 0; i < str.length(); ++i) {
00008     char curr_char = str[i];
00009 
00010     // determine if current character is a separator
00011     bool is_separator = false;
00012     for (size_t j = 0; j < separators.length(); ++j) {
00013       if (curr_char == separators[j]) {
00014         is_separator = true;
00015         break;
00016       }
00017     }
00018 
00019     if (is_separator && curr_token != "") {
00020       // we just completed a token
00021       tokens.push_back(curr_token);
00022       curr_token.clear();
00023     }
00024     else if (!is_separator) {
00025       curr_token += curr_char;
00026     }
00027   }
00028   if (curr_token != "") {
00029     tokens.push_back(curr_token);
00030   }
00031 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends