Add TryParseVector to StringUtil.

Adds a nice way to have options be in a vector for results
This commit is contained in:
Ryan Houdek 2014-07-29 11:34:57 -05:00
parent e4e44909d5
commit 3a657fe33c
1 changed files with 17 additions and 0 deletions

View File

@ -75,6 +75,23 @@ static bool TryParse(const std::string &str, N *const output)
return false;
}
template <typename N>
bool TryParseVector(const std::string& str, std::vector<N>* output, const char delimiter = ',')
{
output->clear();
std::istringstream buffer(str);
std::string variable;
while (std::getline(buffer, variable, delimiter))
{
N tmp = 0;
if (!TryParse(variable, &tmp))
return false;
output->push_back(tmp);
}
return true;
}
// TODO: kill this
bool AsciiToHex(const std::string& _szValue, u32& result);