diff options
| author | 2023-09-03 18:40:03 +0100 | |
|---|---|---|
| committer | 2023-09-03 18:46:48 +0100 | |
| commit | 2f36d0aa2da8b03d525b484228813fbb35f3e35e (patch) | |
| tree | 56a8d2438910db8f7cee76b77b0a9479956adda9 /include | |
| parent | Release v4.0.0 alpha 24. (diff) | |
Move TokenList back to its own header and move INSP_FORMAT to compat.
This allows making stringutils an optional header given that most
of it is not used by most of the codebase.
Diffstat (limited to 'include')
| -rw-r--r-- | include/compat.h | 11 | ||||
| -rw-r--r-- | include/configreader.h | 1 | ||||
| -rw-r--r-- | include/extension.h | 1 | ||||
| -rw-r--r-- | include/inspircd.h | 2 | ||||
| -rw-r--r-- | include/modules/hash.h | 2 | ||||
| -rw-r--r-- | include/stringutils.h | 61 | ||||
| -rw-r--r-- | include/token_list.h | 72 |
7 files changed, 87 insertions, 63 deletions
diff --git a/include/compat.h b/include/compat.h index 4c61a1fc6..8bf0461fd 100644 --- a/include/compat.h +++ b/include/compat.h @@ -32,6 +32,17 @@ # define ATTR_NOT_NULL(...) #endif +/** @def INSP_FORMAT(FORMAT, ...) + * Formats a string with format string checking. + */ +#if defined __cpp_if_constexpr && defined __cpp_return_type_deduction +# include <fmt/compile.h> +# define INSP_FORMAT(FORMAT, ...) fmt::format(FMT_COMPILE(FORMAT), __VA_ARGS__) +#else +# include <fmt/core.h> +# define INSP_FORMAT(FORMAT, ...) fmt::format(FMT_STRING(FORMAT), __VA_ARGS__) +#endif + /** * Windows is very different to UNIX so we have to wrap certain features in * order to build on Windows correctly. diff --git a/include/configreader.h b/include/configreader.h index da712713b..fe92ee312 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -31,7 +31,6 @@ #pragma once #include "inspircd.h" -#include "stringutils.h" /** Represents the position within a file. */ class CoreExport FilePosition final diff --git a/include/extension.h b/include/extension.h index d852eaf9c..2c05b6c7d 100644 --- a/include/extension.h +++ b/include/extension.h @@ -19,6 +19,7 @@ #pragma once +#include "stringutils.h" #include "utility/string.h" /** Base class for types that extend an extensible. */ diff --git a/include/inspircd.h b/include/inspircd.h index 8f16a521c..43a1d86f0 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -79,7 +79,7 @@ CoreExport extern InspIRCd* ServerInstance; #include "numeric.h" #include "uid.h" #include "server.h" -#include "stringutils.h" +#include "token_list.h" #include "users.h" #include "channels.h" #include "timer.h" diff --git a/include/modules/hash.h b/include/modules/hash.h index 5b8dfe625..ae8a161c5 100644 --- a/include/modules/hash.h +++ b/include/modules/hash.h @@ -24,6 +24,8 @@ #pragma once +#include "stringutils.h" + class HashProvider : public DataProvider { diff --git a/include/stringutils.h b/include/stringutils.h index 30710306e..90b3eef1c 100644 --- a/include/stringutils.h +++ b/include/stringutils.h @@ -27,17 +27,6 @@ #pragma once -/** @def INSP_FORMAT(FORMAT, ...) - * Formats a string with format string checking. - */ -#if defined __cpp_if_constexpr && defined __cpp_return_type_deduction -# include <fmt/compile.h> -# define INSP_FORMAT(FORMAT, ...) fmt::format(FMT_COMPILE(FORMAT), __VA_ARGS__) -#else -# include <fmt/core.h> -# define INSP_FORMAT(FORMAT, ...) fmt::format(FMT_STRING(FORMAT), __VA_ARGS__) -#endif - namespace Base64 { /** The default table used when handling Base64-encoded strings. */ @@ -165,53 +154,3 @@ namespace Template */ CoreExport std::string Replace(const std::string& str, const VariableMap& vars); } - -/** Encapsulates a list of tokens in the format "* -FOO -BAR".*/ -class CoreExport TokenList final -{ -private: - /** Whether this list includes all tokens by default. */ - bool permissive = false; - - /** Either the tokens to exclude if in permissive mode or the tokens to include if in strict mode. */ - insp::flat_set<std::string, irc::insensitive_swo> tokens; - -public: - /** Creates a new empty token list. */ - TokenList() = default; - - /** Creates a new token list from a list of tokens. */ - TokenList(const std::string& tokenlist); - - /** Adds a space-delimited list of tokens to the token list. - * @param tokenlist The list of space-delimited tokens to add. - */ - void AddList(const std::string& tokenlist); - - /** Adds a single token to the token list. - * @param token The token to add. - */ - void Add(const std::string& token); - - /** Removes all tokens from the token list. */ - void Clear(); - - /** Determines whether the specified token exists in the token list. - * @param token The token to search for. - */ - bool Contains(const std::string& token) const; - - /** Removes the specified token from the token list. - * @param token The token to remove. - */ - void Remove(const std::string& token); - - /** Retrieves a string which represents the contents of this token list. */ - std::string ToString() const; - - /** Determines whether the specified token list contains the same tokens as this instance. - * @param other The tokenlist to compare against. - * @return True if the token lists are equal; otherwise, false. - */ - bool operator==(const TokenList& other) const; -}; diff --git a/include/token_list.h b/include/token_list.h new file mode 100644 index 000000000..6b6a1e0f6 --- /dev/null +++ b/include/token_list.h @@ -0,0 +1,72 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2017, 2021-2022 Sadie Powell <sadie@witchery.services> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#pragma once + +#include "compat.h" + +/** Encapsulates a list of tokens in the format "* -FOO -BAR".*/ +class CoreExport TokenList final +{ +private: + /** Whether this list includes all tokens by default. */ + bool permissive = false; + + /** Either the tokens to exclude if in permissive mode or the tokens to include if in strict mode. */ + insp::flat_set<std::string, irc::insensitive_swo> tokens; + +public: + /** Creates a new empty token list. */ + TokenList() = default; + + /** Creates a new token list from a list of tokens. */ + TokenList(const std::string& tokenlist); + + /** Adds a space-delimited list of tokens to the token list. + * @param tokenlist The list of space-delimited tokens to add. + */ + void AddList(const std::string& tokenlist); + + /** Adds a single token to the token list. + * @param token The token to add. + */ + void Add(const std::string& token); + + /** Removes all tokens from the token list. */ + void Clear(); + + /** Determines whether the specified token exists in the token list. + * @param token The token to search for. + */ + bool Contains(const std::string& token) const; + + /** Removes the specified token from the token list. + * @param token The token to remove. + */ + void Remove(const std::string& token); + + /** Retrieves a string which represents the contents of this token list. */ + std::string ToString() const; + + /** Determines whether the specified token list contains the same tokens as this instance. + * @param other The tokenlist to compare against. + * @return True if the token lists are equal; otherwise, false. + */ + bool operator==(const TokenList& other) const; +}; |
