diff options
| author | 2022-11-21 13:14:19 +0000 | |
|---|---|---|
| committer | 2022-11-21 13:14:19 +0000 | |
| commit | 07246800fd2e44128adfa09fe91ce10b3ef0bcfc (patch) | |
| tree | 964d9fc4275dc612e5dfb083d2d1abb035fa1719 | |
| parent | Fix iterator_range when the range points to a string_view. (diff) | |
Use string_view in IsNick/IsIdent/IsChannel.
| -rw-r--r-- | include/channelmanager.h | 4 | ||||
| -rw-r--r-- | include/inspircd.h | 8 | ||||
| -rw-r--r-- | src/channelmanager.cpp | 2 | ||||
| -rw-r--r-- | src/helperfuncs.cpp | 6 | ||||
| -rw-r--r-- | src/modules/m_channames.cpp | 6 | ||||
| -rw-r--r-- | src/modules/m_codepage.cpp | 10 |
6 files changed, 18 insertions, 18 deletions
diff --git a/include/channelmanager.h b/include/channelmanager.h index 69acf5a7a..de3d25cf3 100644 --- a/include/channelmanager.h +++ b/include/channelmanager.h @@ -31,14 +31,14 @@ private: public: /** Determines whether an channel name is valid. */ - std::function<bool(const std::string&)> IsChannel = DefaultIsChannel; + std::function<bool(const std::string_view&)> IsChannel = DefaultIsChannel; /** Determines whether a channel name is valid according to the RFC 1459 rules. * This is the default function for InspIRCd::IsChannel. * @param channel The channel name to validate. * @return True if the channel name is valid according to RFC 1459 rules; otherwise, false. */ - static bool DefaultIsChannel(const std::string& channel); + static bool DefaultIsChannel(const std::string_view& channel); /** Finds a channel by name. * @param channel The name of the channel to look up. diff --git a/include/inspircd.h b/include/inspircd.h index 8beeae9b1..0ca6bf8c4 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -373,24 +373,24 @@ public: static std::string Format(va_list& vaList, const char* formatString) ATTR_PRINTF(2, 0); /** Determines whether a nickname is valid. */ - std::function<bool(const std::string&)> IsNick; + std::function<bool(const std::string_view&)> IsNick; /** Determines whether a nickname is valid according to the RFC 1459 rules. * This is the default function for InspIRCd::IsNick. * @param nick The nickname to validate. * @return True if the nickname is valid according to RFC 1459 rules; otherwise, false. */ - static bool DefaultIsNick(const std::string& nick); + static bool DefaultIsNick(const std::string_view& nick); /** Determines whether an ident is valid. */ - std::function<bool(const std::string&)> IsIdent; + std::function<bool(const std::string_view&)> IsIdent; /** Determines whether a ident is valid according to the RFC 1459 rules. * This is the default function for InspIRCd::IsIdent. * @param ident The ident to validate. * @return True if the ident is valid according to RFC 1459 rules; otherwise, false. */ - static bool DefaultIsIdent(const std::string& ident); + static bool DefaultIsIdent(const std::string_view& ident); /** Match two strings using pattern matching, optionally, with a map * to check case against (may be NULL). If map is null, match will be case insensitive. 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<std::string>& 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<bool(const std::string&)> rememberer; + std::function<bool(const std::string_view&)> 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<unsigned char>(*iter); @@ -182,7 +182,7 @@ private: const std::string origcasemapname; // The IsNick handler which was set before this module was loaded. - const std::function<bool(const std::string&)> origisnick; + const std::function<bool(const std::string_view&)> 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; |
