From 07246800fd2e44128adfa09fe91ce10b3ef0bcfc Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 21 Nov 2022 13:14:19 +0000 Subject: Use string_view in IsNick/IsIdent/IsChannel. --- src/channelmanager.cpp | 2 +- src/helperfuncs.cpp | 6 +++--- src/modules/m_channames.cpp | 6 +++--- src/modules/m_codepage.cpp | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp index 9c6137147..9562d2077 100644 --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -19,7 +19,7 @@ #include "inspircd.h" -bool ChannelManager::DefaultIsChannel(const std::string& channel) +bool ChannelManager::DefaultIsChannel(const std::string_view& channel) { if (channel.empty() || channel.length() > ServerInstance->Config->Limits.MaxChannel) return false; diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 1dbc62cb9..6f023cf82 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -158,12 +158,12 @@ void InspIRCd::ProcessColors(std::vector& input) } /* true for valid nickname, false else */ -bool InspIRCd::DefaultIsNick(const std::string& n) +bool InspIRCd::DefaultIsNick(const std::string_view& n) { if (n.empty() || n.length() > ServerInstance->Config->Limits.MaxNick) return false; - for (std::string::const_iterator i = n.begin(); i != n.end(); ++i) + for (std::string_view::const_iterator i = n.begin(); i != n.end(); ++i) { if ((*i >= 'A') && (*i <= '}')) { @@ -185,7 +185,7 @@ bool InspIRCd::DefaultIsNick(const std::string& n) } /* return true for good ident, false else */ -bool InspIRCd::DefaultIsIdent(const std::string& n) +bool InspIRCd::DefaultIsIdent(const std::string_view& n) { if (n.empty()) return false; diff --git a/src/modules/m_channames.cpp b/src/modules/m_channames.cpp index 91806b1d0..5035af5db 100644 --- a/src/modules/m_channames.cpp +++ b/src/modules/m_channames.cpp @@ -29,10 +29,10 @@ static CharState allowedmap; class NewIsChannelHandler final { public: - static bool Call(const std::string&); + static bool Call(const std::string_view&); }; -bool NewIsChannelHandler::Call(const std::string& channame) +bool NewIsChannelHandler::Call(const std::string_view& channame) { if (channame.empty() || channame.length() > ServerInstance->Config->Limits.MaxChannel || !ServerInstance->Channels.IsPrefix(channame[0])) return false; @@ -49,7 +49,7 @@ bool NewIsChannelHandler::Call(const std::string& channame) class ModuleChannelNames final : public Module { - std::function rememberer; + std::function rememberer; bool badchan = false; ChanModeReference permchannelmode; diff --git a/src/modules/m_codepage.cpp b/src/modules/m_codepage.cpp index 350ec617c..a37d0b225 100644 --- a/src/modules/m_codepage.cpp +++ b/src/modules/m_codepage.cpp @@ -75,7 +75,7 @@ public: } // Determines whether a nickname is valid. - virtual bool IsValidNick(const std::string& nick) = 0; + virtual bool IsValidNick(const std::string_view& nick) = 0; // Retrieves the link data for this codepage. virtual void GetLinkData(Module::LinkData& data, std::string& compatdata) const = 0; @@ -112,12 +112,12 @@ public: return ACR_OKAY; } - bool IsValidNick(const std::string& nick) override + bool IsValidNick(const std::string_view& nick) override { if (nick.empty() || nick.length() > ServerInstance->Config->Limits.MaxNick) return false; - for (std::string::const_iterator iter = nick.begin(); iter != nick.end(); ++iter) + for (std::string_view::const_iterator iter = nick.begin(); iter != nick.end(); ++iter) { unsigned char chr = static_cast(*iter); @@ -182,7 +182,7 @@ private: const std::string origcasemapname; // The IsNick handler which was set before this module was loaded. - const std::function origisnick; + const std::function origisnick; // The character set used for the codepage. std::string charset; @@ -313,7 +313,7 @@ public: charset = codepagetag->getString("charset"); std::swap(codepage, newcodepage); - ServerInstance->IsNick = [this](const std::string& nick) { return codepage->IsValidNick(nick); }; + ServerInstance->IsNick = [this](const std::string_view& nick) { return codepage->IsValidNick(nick); }; CheckInvalidNick(); ServerInstance->Config->CaseMapping = name; -- cgit v1.3.1-10-gc9f91