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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Oct 10 06:18:36 UTC 2016


 loolwsd/LOOLProtocol.hpp   |   15 ++++++++-------
 loolwsd/test/UnitFonts.cpp |    4 ++--
 2 files changed, 10 insertions(+), 9 deletions(-)

New commits:
commit f7327115debc9c9d18f061ba9baef8fb993cc9de
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Oct 8 13:12:16 2016 -0400

    loolwsd: allow for delimiter in LOOLProtocol parsers
    
    Change-Id: I9c7e503aed067dfe36953552237941e7c1841457
    Reviewed-on: https://gerrit.libreoffice.org/29633
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp
index e5e79b9..6120e0c 100644
--- a/loolwsd/LOOLProtocol.hpp
+++ b/loolwsd/LOOLProtocol.hpp
@@ -75,29 +75,29 @@ namespace LOOLProtocol
     bool parseStatus(const std::string& message, LibreOfficeKitDocumentType& type, int& nParts, int& currentPart, int& width, int& height);
 
     inline
-    std::string getDelimitedInitialSubstring(const char *message, const int length, const char delimiter)
+    std::string getDelimitedInitialSubstring(const char *message, const int length, const char delim)
     {
         if (message == nullptr || length <= 0)
         {
             return "";
         }
 
-        const char *foundDelimiter = static_cast<const char *>(std::memchr(message, delimiter, length));
-        const auto size = (foundDelimiter == nullptr ? length : foundDelimiter - message);
+        const char *founddelim = static_cast<const char *>(std::memchr(message, delim, length));
+        const auto size = (founddelim == nullptr ? length : founddelim - message);
         return std::string(message, size);
     }
 
     /// Returns the first token of a message.
     inline
-    std::string getFirstToken(const char *message, const int length)
+    std::string getFirstToken(const char *message, const int length, const char delim)
     {
-        return getDelimitedInitialSubstring(message, length, ' ');
+        return getDelimitedInitialSubstring(message, length, delim);
     }
 
     template <typename T>
-    std::string getFirstToken(const T& message)
+    std::string getFirstToken(const T& message, const char delim = ' ')
     {
-        return getFirstToken(message.data(), message.size());
+        return getFirstToken(message.data(), message.size(), delim);
     }
 
     /// Returns true if the token is a user-interaction token.
@@ -126,6 +126,7 @@ namespace LOOLProtocol
         return getDelimitedInitialSubstring(message, length, '\n');
     }
 
+    /// Returns the first line of any data which payload char*.
     template <typename T>
     std::string getFirstLine(const T& message)
     {
diff --git a/loolwsd/test/UnitFonts.cpp b/loolwsd/test/UnitFonts.cpp
index 2d1b157..c82dcbb 100644
--- a/loolwsd/test/UnitFonts.cpp
+++ b/loolwsd/test/UnitFonts.cpp
@@ -144,10 +144,10 @@ public:
     virtual bool filterKitMessage(const std::shared_ptr<Poco::Net::WebSocket> &ws,
                                   std::string &message) override
     {
-        std::string token = LOOLProtocol::getFirstToken(message.c_str(), message.length());
+        const std::string token = LOOLProtocol::getFirstToken(message);
         if (token == "unit-getfontlist:")
         {
-            std::string fontListReply = getFontList() + "\n";
+            const std::string fontListReply = getFontList() + "\n";
             ws->sendFrame(fontListReply.c_str(), fontListReply.length());
             return true;
         }


More information about the Libreoffice-commits mailing list