[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp
Tor Lillqvist
tml at collabora.com
Mon Apr 11 07:15:07 UTC 2016
loolwsd/LOOLProtocol.hpp | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
New commits:
commit a598ea869cb6684263e7c1961f2dd43613e56b4b
Author: Tor Lillqvist <tml at collabora.com>
Date: Mon Apr 11 10:11:49 2016 +0300
Use less misleading function and variable names
Also, get rid of one default parameter that was passed a non-default
value only 'internally'.
diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp
index 66276b1..0ed166a 100644
--- a/loolwsd/LOOLProtocol.hpp
+++ b/loolwsd/LOOLProtocol.hpp
@@ -43,20 +43,26 @@ namespace LOOLProtocol
// Functions that parse messages. All return false if parsing fails
bool parseStatus(const std::string& message, LibreOfficeKitDocumentType& type, int& nParts, int& currentPart, int& width, int& height);
- /// Returns the first token of a message given a delimiter.
inline
- std::string getFirstToken(const char *message, const int length, const char delim = ' ')
+ std::string getDelimitedInitialSubstring(const char *message, const int length, const char delimiter)
{
if (message == nullptr || length <= 0)
{
return "";
}
- const char *endOfLine = static_cast<const char *>(std::memchr(message, delim, length));
- const auto size = (endOfLine == nullptr ? length : endOfLine - message);
+ const char *foundDelimiter = static_cast<const char *>(std::memchr(message, delimiter, length));
+ const auto size = (foundDelimiter == nullptr ? length : foundDelimiter - message);
return std::string(message, size);
}
+ /// Returns the first token of a message.
+ inline
+ std::string getFirstToken(const char *message, const int length)
+ {
+ return getDelimitedInitialSubstring(message, length, ' ');
+ }
+
inline
std::string getFirstToken(const std::vector<char>& message)
{
@@ -81,7 +87,7 @@ namespace LOOLProtocol
inline
std::string getFirstLine(const char *message, const int length)
{
- return getFirstToken(message, length, '\n');
+ return getDelimitedInitialSubstring(message, length, '\n');
}
inline
More information about the Libreoffice-commits
mailing list