[ create a new paste ] login | about

Link: http://codepad.org/8O4yos5l    [ raw code | fork ]

C++, pasted on Aug 12:
/*
 * Tokenizer which also returns the delimiters as tokens
 */
vector<string> tokenizer(const string input, const string delimiters) {
    
    vector<string> tokens;
    
    string::const_iterator inputIt;
    string::const_iterator delimIt;
    
    string tmp = "";
    bool foundDelim = false;
    
    for(input.begin(); inputIt<input.end(); inputIt++) {
        
        for(delimiters.begin(); delimIt<delimiters.end(); delimIt++) {
            
            if(*inputIt == *delimIt) {
                foundDelim = true;
                break;
            }
            
        }
        
        if(foundDelim) {
            
            if(tmp != "") {
                tokens.push_back(tmp);
            }
            
            tokens.push_back(string(*const_cast<char*>(delimIt)));
        
            tmp = "";
            
        } else {
            
            tmp += *inputIt;
        }
        
    }
    
    return tokens;
}


Create a new paste based on this one


Comments: