[Common] Update stdstr::Tokenize to handle empty items
This commit is contained in:
parent
169f9d92bf
commit
2d7524ae2f
|
@ -30,12 +30,17 @@ strvector stdstr::Tokenize(const char * delimiter) const
|
||||||
|
|
||||||
stdstr::size_type lastPos = find_first_not_of(delimiter, 0);
|
stdstr::size_type lastPos = find_first_not_of(delimiter, 0);
|
||||||
stdstr::size_type pos = find_first_of(delimiter, lastPos);
|
stdstr::size_type pos = find_first_of(delimiter, lastPos);
|
||||||
while (stdstr::npos != pos || stdstr::npos != lastPos)
|
size_t delimiter_len = strlen(delimiter);
|
||||||
|
while (stdstr::npos != pos)
|
||||||
{
|
{
|
||||||
tokens.push_back(substr(lastPos, pos - lastPos));
|
tokens.push_back(substr(lastPos, pos - lastPos));
|
||||||
lastPos = find_first_not_of(delimiter, pos);
|
lastPos = pos + delimiter_len;
|
||||||
pos = find_first_of(delimiter, lastPos);
|
pos = find_first_of(delimiter, lastPos);
|
||||||
}
|
}
|
||||||
|
if (stdstr::npos != lastPos)
|
||||||
|
{
|
||||||
|
tokens.push_back(substr(lastPos));
|
||||||
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +50,16 @@ strvector stdstr::Tokenize(char delimiter) const
|
||||||
|
|
||||||
stdstr::size_type lastPos = find_first_not_of(delimiter, 0);
|
stdstr::size_type lastPos = find_first_not_of(delimiter, 0);
|
||||||
stdstr::size_type pos = find_first_of(delimiter, lastPos);
|
stdstr::size_type pos = find_first_of(delimiter, lastPos);
|
||||||
while (stdstr::npos != pos || stdstr::npos != lastPos)
|
while (stdstr::npos != pos)
|
||||||
{
|
{
|
||||||
tokens.push_back(substr(lastPos, pos - lastPos));
|
tokens.push_back(substr(lastPos, pos - lastPos));
|
||||||
lastPos = find_first_not_of(delimiter, pos);
|
lastPos = pos + 1;
|
||||||
pos = find_first_of(delimiter, lastPos);
|
pos = find_first_of(delimiter, lastPos);
|
||||||
}
|
}
|
||||||
|
if (stdstr::npos != lastPos)
|
||||||
|
{
|
||||||
|
tokens.push_back(substr(lastPos));
|
||||||
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue