diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index 2d2e3be25..34be792f3 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -162,7 +162,7 @@ bool CaselessCmp::operator()(const std::string &a, const std::string &b) const return less(a, b); } -bool CaselessCmp::less(const std::string &a, const std::string &b) +bool CaselessCmp::less(const std::string_view &a, const std::string_view &b) { return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), &deskflow::string::CaselessCmp::cmpLess); } diff --git a/src/lib/base/String.h b/src/lib/base/String.h index 622f30818..b2d9a6bcc 100644 --- a/src/lib/base/String.h +++ b/src/lib/base/String.h @@ -67,7 +67,7 @@ public: bool operator()(const std::string &a, const std::string &b) const; //! Returns true iff \c a is lexicographically less than \c b - static bool less(const std::string &a, const std::string &b); + static bool less(const std::string_view &a, const std::string_view &b); //! Returns true iff \c a is lexicographically equal to \c b static bool equal(const std::string &a, const std::string &b); diff --git a/src/lib/base/Unicode.cpp b/src/lib/base/Unicode.cpp index 509a60fc5..d2024b0f9 100644 --- a/src/lib/base/Unicode.cpp +++ b/src/lib/base/Unicode.cpp @@ -226,7 +226,7 @@ std::string Unicode::UCS2ToUTF8(const std::string &src, bool *errors) return doUCS2ToUTF8(reinterpret_cast(src.data()), n, errors); } -std::string Unicode::UCS4ToUTF8(const std::string &src, bool *errors) +std::string Unicode::UCS4ToUTF8(const std::string_view &src, bool *errors) { // default to success resetError(errors); @@ -236,7 +236,7 @@ std::string Unicode::UCS4ToUTF8(const std::string &src, bool *errors) return doUCS4ToUTF8(reinterpret_cast(src.data()), n, errors); } -std::string Unicode::UTF16ToUTF8(const std::string &src, bool *errors) +std::string Unicode::UTF16ToUTF8(const std::string_view &src, bool *errors) { // default to success resetError(errors); @@ -246,7 +246,7 @@ std::string Unicode::UTF16ToUTF8(const std::string &src, bool *errors) return doUTF16ToUTF8(reinterpret_cast(src.data()), n, errors); } -std::string Unicode::UTF32ToUTF8(const std::string &src, bool *errors) +std::string Unicode::UTF32ToUTF8(const std::string_view &src, bool *errors) { // default to success resetError(errors); diff --git a/src/lib/base/Unicode.h b/src/lib/base/Unicode.h index 66144f8f0..ee453d0b3 100644 --- a/src/lib/base/Unicode.h +++ b/src/lib/base/Unicode.h @@ -81,21 +81,21 @@ public: Convert from UCS-4 to UTF-8. If errors is not nullptr then *errors is set to true iff any character could not be decoded. */ - static std::string UCS4ToUTF8(const std::string &, bool *errors = nullptr); + static std::string UCS4ToUTF8(const std::string_view &, bool *errors = nullptr); //! Convert from UTF-16 to UTF-8 /*! Convert from UTF-16 to UTF-8. If errors is not nullptr then *errors is set to true iff any character could not be decoded. */ - static std::string UTF16ToUTF8(const std::string &, bool *errors = nullptr); + static std::string UTF16ToUTF8(const std::string_view &, bool *errors = nullptr); //! Convert from UTF-32 to UTF-8 /*! Convert from UTF-32 to UTF-8. If errors is not nullptr then *errors is set to true iff any character could not be decoded. */ - static std::string UTF32ToUTF8(const std::string &, bool *errors = nullptr); + static std::string UTF32ToUTF8(const std::string_view &, bool *errors = nullptr); //! Convert from the current locale encoding to UTF-8 /*! diff --git a/src/lib/deskflow/ArgParser.cpp b/src/lib/deskflow/ArgParser.cpp index 1875e583d..7c016fefd 100644 --- a/src/lib/deskflow/ArgParser.cpp +++ b/src/lib/deskflow/ArgParser.cpp @@ -232,7 +232,7 @@ bool ArgParser::isArg( return false; } -void ArgParser::splitCommandString(const std::string &command, std::vector &argv) +void ArgParser::splitCommandString(const std::string_view &command, std::vector &argv) { if (command.empty()) { return; @@ -256,10 +256,10 @@ void ArgParser::splitCommandString(const std::string &command, std::vector &argv); - static bool searchDoubleQuotes(const std::string &command, size_t &left, size_t &right, size_t startPos = 0); - static void removeDoubleQuotes(std::string &arg); + static void splitCommandString(const std::string_view &command, std::vector &argv); + static bool searchDoubleQuotes(const std::string_view &command, size_t &left, size_t &right, size_t startPos = 0); + static void removeDoubleQuotes(std::string_view &arg); static const char **getArgv(std::vector &argsArray); static std::string assembleCommand(std::vector &argsArray, std::string ignoreArg = "", int parametersRequired = 0); diff --git a/src/lib/deskflow/IClipboard.cpp b/src/lib/deskflow/IClipboard.cpp index 6c01e902d..4846ce448 100644 --- a/src/lib/deskflow/IClipboard.cpp +++ b/src/lib/deskflow/IClipboard.cpp @@ -13,7 +13,7 @@ // IClipboard // -void IClipboard::unmarshall(IClipboard *clipboard, const std::string &data, Time time) +void IClipboard::unmarshall(IClipboard *clipboard, const std::string_view &data, Time time) { assert(clipboard != nullptr); diff --git a/src/lib/deskflow/IClipboard.h b/src/lib/deskflow/IClipboard.h index 596c3cc0a..89715426c 100644 --- a/src/lib/deskflow/IClipboard.h +++ b/src/lib/deskflow/IClipboard.h @@ -131,7 +131,7 @@ public: Extract marshalled clipboard data and store it in \p clipboard. Sets the clipboard time to \c time. */ - static void unmarshall(IClipboard *clipboard, const std::string &data, Time time); + static void unmarshall(IClipboard *clipboard, const std::string_view &data, Time time); //! Copy clipboard /*! diff --git a/src/lib/deskflow/IKeyState.cpp b/src/lib/deskflow/IKeyState.cpp index 00bdc7589..2027d0a4f 100644 --- a/src/lib/deskflow/IKeyState.cpp +++ b/src/lib/deskflow/IKeyState.cpp @@ -72,7 +72,7 @@ bool IKeyState::KeyInfo::isDefault(const char *screens) return (screens == nullptr || screens[0] == '\0'); } -bool IKeyState::KeyInfo::contains(const char *screens, const std::string &name) +bool IKeyState::KeyInfo::contains(const char *screens, const std::string_view &name) { // special cases if (isDefault(screens)) { diff --git a/src/lib/deskflow/IKeyState.h b/src/lib/deskflow/IKeyState.h index 2b57cafc4..6c3f3795f 100644 --- a/src/lib/deskflow/IKeyState.h +++ b/src/lib/deskflow/IKeyState.h @@ -39,7 +39,7 @@ public: static KeyInfo *alloc(const KeyInfo &); static bool isDefault(const char *screens); - static bool contains(const char *screens, const std::string &name); + static bool contains(const char *screens, const std::string_view &name); static bool equal(const KeyInfo *, const KeyInfo *); static std::string join(const std::set &destinations); static void split(const char *screens, std::set &); diff --git a/src/lib/deskflow/ServerApp.cpp b/src/lib/deskflow/ServerApp.cpp index 9d2b3ec8b..e96e5b81d 100644 --- a/src/lib/deskflow/ServerApp.cpp +++ b/src/lib/deskflow/ServerApp.cpp @@ -269,7 +269,7 @@ void ServerApp::updateStatus() updateStatus(""); } -void ServerApp::updateStatus(const std::string &msg) const +void ServerApp::updateStatus(const std::string_view &msg) const { // do nothing } diff --git a/src/lib/deskflow/ServerApp.h b/src/lib/deskflow/ServerApp.h index b95f43310..c43f36a3a 100644 --- a/src/lib/deskflow/ServerApp.h +++ b/src/lib/deskflow/ServerApp.h @@ -86,7 +86,7 @@ public: void closeServer(Server *server); void stopRetryTimer(); void updateStatus(); - void updateStatus(const std::string &msg) const; + void updateStatus(const std::string_view &msg) const; void closeClientListener(ClientListener *listen); void stopServer(); void closePrimaryClient(PrimaryClient *primaryClient); diff --git a/src/lib/deskflow/StreamChunker.cpp b/src/lib/deskflow/StreamChunker.cpp index b57354fc9..c60fcf870 100644 --- a/src/lib/deskflow/StreamChunker.cpp +++ b/src/lib/deskflow/StreamChunker.cpp @@ -23,7 +23,7 @@ using namespace std; static const size_t g_chunkSize = 512 * 1024; // 512kb void StreamChunker::sendClipboard( - const std::string &data, size_t size, ClipboardID id, uint32_t sequence, IEventQueue *events, void *eventTarget + const std::string_view &data, size_t size, ClipboardID id, uint32_t sequence, IEventQueue *events, void *eventTarget ) { // send first message (data size) @@ -42,7 +42,7 @@ void StreamChunker::sendClipboard( chunkSize = size - sentLength; } - std::string chunk(data.substr(sentLength, chunkSize).c_str(), chunkSize); + std::string chunk(data.substr(sentLength, chunkSize).data(), chunkSize); ClipboardChunk *dataChunk = ClipboardChunk::data(id, sequence, chunk); events->addEvent(Event(EventTypes::ClipboardSending, eventTarget, dataChunk)); diff --git a/src/lib/deskflow/languages/LanguageManager.cpp b/src/lib/deskflow/languages/LanguageManager.cpp index bd7f01787..ef2007f68 100644 --- a/src/lib/deskflow/languages/LanguageManager.cpp +++ b/src/lib/deskflow/languages/LanguageManager.cpp @@ -11,7 +11,7 @@ namespace { -std::string vectorToString(const std::vector &vector, const std::string &delimiter = "") +std::string vectorToString(const std::vector &vector, const std::string_view &delimiter = "") { std::string string; for (const auto &item : vector) { @@ -34,12 +34,13 @@ LanguageManager::LanguageManager(const std::vector &localLanguages) LOG((CLOG_INFO "local languages: %s", vectorToString(m_localLanguages, ", ").c_str())); } -void LanguageManager::setRemoteLanguages(const std::string &remoteLanguages) +void LanguageManager::setRemoteLanguages(const std::string_view &remoteLanguages) { m_remoteLanguages.clear(); if (!remoteLanguages.empty()) { for (size_t i = 0; i <= remoteLanguages.size() - 2; i += 2) { - m_remoteLanguages.push_back(remoteLanguages.substr(i, 2)); + auto rLangs = remoteLanguages.substr(i, 2); + m_remoteLanguages.push_back(std::string{rLangs.begin(), rLangs.end()}); } } LOG((CLOG_INFO "remote languages: %s", vectorToString(m_remoteLanguages, ", ").c_str())); diff --git a/src/lib/deskflow/languages/LanguageManager.h b/src/lib/deskflow/languages/LanguageManager.h index d6fbf3192..68cd49c26 100644 --- a/src/lib/deskflow/languages/LanguageManager.h +++ b/src/lib/deskflow/languages/LanguageManager.h @@ -27,7 +27,7 @@ public: * @brief setRemoteLanguages sets remote languages * @param remoteLanguages is a string with sericalized languages */ - void setRemoteLanguages(const std::string &remoteLanguages); + void setRemoteLanguages(const std::string_view &remoteLanguages); /** * @brief getRemoteLanguages getter for remote languages diff --git a/src/lib/deskflow/unix/X11LayoutsParser.cpp b/src/lib/deskflow/unix/X11LayoutsParser.cpp index ba07fd9d7..540438a65 100644 --- a/src/lib/deskflow/unix/X11LayoutsParser.cpp +++ b/src/lib/deskflow/unix/X11LayoutsParser.cpp @@ -95,7 +95,7 @@ std::vector X11LayoutsParser::getAllLanguageData(const s void X11LayoutsParser::appendVectorUniq(const std::vector &source, std::vector &dst) { for (const auto &elem : source) { - if (std::find_if(dst.begin(), dst.end(), [elem](const std::string &s) { return s == elem; }) == dst.end()) { + if (std::find_if(dst.begin(), dst.end(), [elem](const std::string_view &s) { return s == elem; }) == dst.end()) { dst.push_back(elem); } } diff --git a/src/lib/server/Config.cpp b/src/lib/server/Config.cpp index aaf24324d..344c36b69 100644 --- a/src/lib/server/Config.cpp +++ b/src/lib/server/Config.cpp @@ -1147,7 +1147,7 @@ void Config::parseAction( rule.adoptAction(action, activate); } -void Config::parseScreens(const ConfigReadContext &c, const std::string &s, std::set &screens) const +void Config::parseScreens(const ConfigReadContext &c, const std::string_view &s, std::set &screens) const { screens.clear(); @@ -1370,7 +1370,7 @@ Config::CellEdge::CellEdge(const std::string &name, EDirection side, const Inter init(name, side, interval); } -void Config::CellEdge::init(const std::string &name, EDirection side, const Interval &interval) +void Config::CellEdge::init(const std::string_view &name, EDirection side, const Interval &interval) { assert(side != kNoDirection); @@ -1384,7 +1384,7 @@ Config::Interval Config::CellEdge::getInterval() const return m_interval; } -void Config::CellEdge::setName(const std::string &newName) +void Config::CellEdge::setName(const std::string_view &newName) { m_name = newName; } diff --git a/src/lib/server/Config.h b/src/lib/server/Config.h index 4fd8df886..4640902bc 100644 --- a/src/lib/server/Config.h +++ b/src/lib/server/Config.h @@ -64,7 +64,7 @@ public: ~CellEdge() = default; Interval getInterval() const; - void setName(const std::string &newName); + void setName(const std::string_view &newName); std::string getName() const; EDirection getSide() const; bool overlaps(const CellEdge &) const; @@ -84,7 +84,7 @@ public: bool operator!=(const CellEdge &) const; private: - void init(const std::string &name, EDirection side, const Interval &); + void init(const std::string_view &name, EDirection side, const Interval &); private: std::string m_name; @@ -474,7 +474,7 @@ private: bool activate ); - void parseScreens(const ConfigReadContext &, const std::string &, std::set &screens) const; + void parseScreens(const ConfigReadContext &, const std::string_view &, std::set &screens) const; static const char *getOptionName(OptionID); static std::string getOptionValue(OptionID, OptionValue); diff --git a/src/lib/server/InputFilter.cpp b/src/lib/server/InputFilter.cpp index bdaec85bb..0d81ef852 100644 --- a/src/lib/server/InputFilter.cpp +++ b/src/lib/server/InputFilter.cpp @@ -845,7 +845,7 @@ void InputFilter::setPrimaryClient(PrimaryClient *client) } } -std::string InputFilter::format(const std::string &linePrefix) const +std::string InputFilter::format(const std::string_view &linePrefix) const { std::string s; for (auto i = m_ruleList.begin(); i != m_ruleList.end(); ++i) { diff --git a/src/lib/server/InputFilter.h b/src/lib/server/InputFilter.h index 71aff127f..9f7a27944 100644 --- a/src/lib/server/InputFilter.h +++ b/src/lib/server/InputFilter.h @@ -375,7 +375,7 @@ public: virtual void setPrimaryClient(PrimaryClient *client); // convert rules to a string - std::string format(const std::string &linePrefix) const; + std::string format(const std::string_view &linePrefix) const; // get number of rules uint32_t getNumRules() const;