Use string_view in InspIRCd::Is{FQDN,Host,SID}.

This commit is contained in:
Sadie Powell 2024-09-07 19:16:48 +01:00
parent 83e142fa2f
commit 73a98ce7be
2 changed files with 8 additions and 8 deletions

View File

@ -340,20 +340,20 @@ public:
* @param host The hostname to validate.
* @return True if the hostname is valid; otherwise, false.
*/
inline static auto IsFQDN(const std::string& host) { return IsHost(host, false); }
inline static auto IsFQDN(const std::string_view& host) { return IsHost(host, false); }
/** Determines whether a hostname is valid according to RFC 5891 rules.
* @param host The hostname to validate.
* @param allowsimple Whether to allow simple hostnames (e.g. localhost).
* @return True if the hostname is valid; otherwise, false.
*/
static bool IsHost(const std::string& host, bool allowsimple);
static bool IsHost(const std::string_view& host, bool allowsimple);
/** Determines whether the specified string is a server identifier.
* @param sid The string to check.
* @return True if the specified string is a server identifier; otherwise, false.
*/
static bool IsSID(const std::string& sid);
static bool IsSID(const std::string_view& sid);
/** Determines whether the specified string is a valid nick!user\@host mask.
* @param mask The string to check.

View File

@ -292,7 +292,7 @@ bool InspIRCd::DefaultIsUser(const std::string_view& n)
return true;
}
bool InspIRCd::IsHost(const std::string& host, bool allowsimple)
bool InspIRCd::IsHost(const std::string_view& host, bool allowsimple)
{
// Hostnames must be non-empty and shorter than the maximum hostname length.
if (host.empty() || host.length() > ServerInstance->Config->Limits.MaxHost)
@ -301,10 +301,10 @@ bool InspIRCd::IsHost(const std::string& host, bool allowsimple)
unsigned int numdashes = 0;
unsigned int numdots = 0;
bool seendot = false;
const std::string::const_iterator hostend = host.end() - 1;
for (std::string::const_iterator iter = host.begin(); iter != host.end(); ++iter)
const auto hostend = host.end() - 1;
for (auto iter = host.begin(); iter != host.end(); ++iter)
{
unsigned char chr = static_cast<unsigned char>(*iter);
const auto chr = static_cast<unsigned char>(*iter);
// If the current character is a label separator.
if (chr == '.')
@ -351,7 +351,7 @@ bool InspIRCd::IsHost(const std::string& host, bool allowsimple)
return numdots || allowsimple;
}
bool InspIRCd::IsSID(const std::string& str)
bool InspIRCd::IsSID(const std::string_view& str)
{
/* Returns true if the string given is exactly 3 characters long,
* starts with a digit, and the other two characters are A-Z or digits