[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.cpp loolwsd/LOOLProtocol.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun May 15 22:55:50 UTC 2016


 loolwsd/LOOLProtocol.cpp |   17 +++++++++++++++--
 loolwsd/LOOLProtocol.hpp |    1 +
 2 files changed, 16 insertions(+), 2 deletions(-)

New commits:
commit a11c1b5483ca43e6a9c676e59499b1c830bfe32c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
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 <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

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);


More information about the Libreoffice-commits mailing list