00001 #ifndef TOKENIZE_H
00002 #define TOKENIZE_H
00003
00004 #include <string>
00005 #include <vector>
00006
00007 namespace util
00008 {
00009
00018 inline std::vector<std::string> tokenize(const char input[])
00019 {
00020 std::vector<std::string> token;
00021 bool betweenWords = true;
00022 int start = 0;
00023 int i;
00024 for(i = 0; input[i] != '\0'; i++) {
00025 const bool isSpace = (input[i] == ' ' || input[i] == '\t');
00026
00027 if (!isSpace && betweenWords) {
00028 start = i;
00029 betweenWords = false;
00030 } else if (isSpace && !betweenWords) {
00031 token.push_back( std::string( input+start, i-start ) );
00032 betweenWords = true;
00033 }
00034 }
00035 if (!betweenWords)
00036 token.push_back( std::string( input+start, i-start ) );
00037 return token;
00038 }
00039
00044 inline std::vector<std::string> tokenize(const std::string &input)
00045 {
00046 return tokenize(input.c_str());
00047 }
00048
00049 }
00050
00051 #endif