loolwsd/LOOLProtocol.cpp | 17 +++++++++++++++-- loolwsd/LOOLProtocol.hpp | 1 + 2 files changed, 16 insertions(+), 2 deletions(-)
New commits: commit a11c1b5483ca43e6a9c676e59499b1c830bfe32c Author: Ashod Nakashian <[email protected]> Date: Sun May 15 17:44:40 2016 -0400 loolwsd: new token parser helper Change-Id: I29af7aefe68c4673e21fe11c2ac469cfc87c1a2c Reviewed-on: https://gerrit.libreoffice.org/25018 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/LOOLProtocol.cpp b/loolwsd/LOOLProtocol.cpp index 2d5893b..b04222c 100644 --- a/loolwsd/LOOLProtocol.cpp +++ b/loolwsd/LOOLProtocol.cpp @@ -57,6 +57,18 @@ namespace LOOLProtocol return true; } + bool parseNameIntegerPair(const std::string& token, std::string& name, int& value) + { + const auto mid = token.find_first_of('='); + if (mid != std::string::npos) + { + name = token.substr(0, mid); + return stringToInteger(token.substr(mid + 1), value); + } + + return false; + } + bool getTokenInteger(const std::string& token, const std::string& name, int& value) { size_t nextIdx; @@ -68,7 +80,7 @@ namespace LOOLProtocol (value = std::stoi(token.substr(name.size() + 1), &nextIdx), false) || nextIdx != token.size() - name.size() - 1) { - throw std::invalid_argument("bah"); + return false; } } catch (std::invalid_argument&) @@ -87,13 +99,14 @@ namespace LOOLProtocol token.substr(0, name.size()) != name || token[name.size()] != '=') { - throw std::invalid_argument("bah"); + return false; } } catch (std::invalid_argument&) { return false; } + value = token.substr(name.size() + 1); return true; } diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 21d488b..842429c 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -37,6 +37,7 @@ namespace LOOLProtocol std::tuple<int, int, std::string> ParseVersion(const std::string& version); bool stringToInteger(const std::string& input, int& value); + bool parseNameIntegerPair(const std::string& token, std::string& name, int& value); bool getTokenInteger(const std::string& token, const std::string& name, int& value); bool getTokenString(const std::string& token, const std::string& name, std::string& value); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
