From 3a657fe33c4d1bb060a3a67e00d2334c40dde541 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Tue, 29 Jul 2014 11:34:57 -0500 Subject: [PATCH] Add TryParseVector to StringUtil. Adds a nice way to have options be in a vector for results --- Source/Core/Common/StringUtil.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h index 50d270e732..8e9e9315af 100644 --- a/Source/Core/Common/StringUtil.h +++ b/Source/Core/Common/StringUtil.h @@ -75,6 +75,23 @@ static bool TryParse(const std::string &str, N *const output) return false; } +template +bool TryParseVector(const std::string& str, std::vector* 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);