Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringUtils::Tokenize: clarify, simplify and optimize #4982

Merged
merged 1 commit into from
Jul 3, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions xbmc/utils/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,19 +1164,16 @@ std::vector<std::string> StringUtils::Tokenize(const std::string &input, const s

void StringUtils::Tokenize(const std::string& input, std::vector<std::string>& tokens, const std::string& delimiters)
{
// Tokenize ripped from http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-7.html
tokens.clear();

This comment was marked as spam.

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

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

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.