コード例 #1
0
ファイル: Common.cpp プロジェクト: nightwing/npp
std::vector<generic_string> tokenizeString(const generic_string & tokenString, const char delim) {
    //Vector is created on stack and copied on return
    std::vector<generic_string> tokens;

    // Skip delimiters at beginning.
    generic_string::size_type lastPos = tokenString.find_first_not_of(delim, 0);
    // Find first "non-delimiter".
    generic_string::size_type pos     = tokenString.find_first_of(delim, lastPos);

    while (pos != std::string::npos || lastPos != std::string::npos)
    {
        // Found a token, add it to the vector.
        tokens.push_back(tokenString.substr(lastPos, pos - lastPos));
        // Skip delimiters.  Note the "not_of"
        lastPos = tokenString.find_first_not_of(delim, pos);
        // Find next "non-delimiter"
        pos = tokenString.find_first_of(delim, lastPos);
    }
    return tokens;
}