From e6e812c43c3183316c5222f55ae1ed448108623a Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 2 Aug 2025 17:04:03 +0100 Subject: [PATCH] Move NormalizeBuffer to textproc and rename more descriptively. --- include/anope.h | 6 ------ include/textproc.h | 6 ++++++ modules/botserv/bs_kick.cpp | 2 +- modules/fantasy.cpp | 4 ++-- modules/rpc/rpc_user.cpp | 2 +- src/misc.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/anope.h b/include/anope.h index f04dc640b..3fad88ef4 100644 --- a/include/anope.h +++ b/include/anope.h @@ -531,12 +531,6 @@ namespace Anope */ extern CoreExport Anope::string strftime(time_t t, const NickCore *nc = NULL, bool short_output = false); - /** Normalize buffer, stripping control characters and colors - * @param A string to be parsed for control and color codes - * @return A string stripped of control and color codes - */ - extern CoreExport Anope::string NormalizeBuffer(const Anope::string &); - /** Parses a raw message from the uplink and calls its command handler. * @param message Raw message from the uplink */ diff --git a/include/textproc.h b/include/textproc.h index 376dd8f56..0c8c85867 100644 --- a/include/textproc.h +++ b/include/textproc.h @@ -49,6 +49,12 @@ namespace Anope */ extern CoreExport bool ParseCTCP(const Anope::string &text, Anope::string &name, Anope::string &body); + /** Remove all formatting characters from a string. + * @param text A string containing formatting characters. + * @return A copy of \p text with all formatting characters removed. + */ + extern CoreExport Anope::string RemoveFormatting(const Anope::string &text); + /** Replaces template variables within a string with values from a map. * @param str The string to template from. * @param vars The variables to replace within the string. diff --git a/modules/botserv/bs_kick.cpp b/modules/botserv/bs_kick.cpp index 97ca62d54..c92735407 100644 --- a/modules/botserv/bs_kick.cpp +++ b/modules/botserv/bs_kick.cpp @@ -1369,7 +1369,7 @@ public: BadWords *badwords = ci->GetExt("badwords"); /* Normalize the buffer */ - Anope::string nbuf = Anope::NormalizeBuffer(realbuf); + Anope::string nbuf = Anope::RemoveFormatting(realbuf); bool casesensitive = Config->GetModule("botserv").Get("casesensitive"); /* Normalize can return an empty string if this only contains control codes etc */ diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp index 2dd28d244..da6cc9bcc 100644 --- a/modules/fantasy.cpp +++ b/modules/fantasy.cpp @@ -110,7 +110,7 @@ public: if (params.empty()) return; - Anope::string normalized_param0 = Anope::NormalizeBuffer(params[0]); + Anope::string normalized_param0 = Anope::RemoveFormatting(params[0]); Anope::string fantasy_chars = Config->GetModule(this).Get("fantasycharacter", "!"); if (!normalized_param0.find(c->ci->bi->nick)) @@ -143,7 +143,7 @@ public: full_command.erase(full_command.begin()); ++count; - it = Config->Fantasy.find(Anope::NormalizeBuffer(full_command)); + it = Config->Fantasy.find(Anope::RemoveFormatting(full_command)); } if (it == Config->Fantasy.end()) diff --git a/modules/rpc/rpc_user.cpp b/modules/rpc/rpc_user.cpp index 00e099f92..208ed1412 100644 --- a/modules/rpc/rpc_user.cpp +++ b/modules/rpc/rpc_user.cpp @@ -235,7 +235,7 @@ private: void SendMessage(BotInfo *source, const Anope::string &msg) override { - root.Reply(NormalizeBuffer(msg.replace_all_cs("\x1A", "\x20"))); + root.Reply(Anope::RemoveFormatting(msg.replace_all_cs("\x1A", "\x20"))); }; }; diff --git a/src/misc.cpp b/src/misc.cpp index 61c8dcd94..4ed01ecf6 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -822,7 +822,7 @@ int Anope::VersionMajor() { return VERSION_MAJOR; } int Anope::VersionMinor() { return VERSION_MINOR; } int Anope::VersionPatch() { return VERSION_PATCH; } -Anope::string Anope::NormalizeBuffer(const Anope::string &buf) +Anope::string Anope::RemoveFormatting(const Anope::string &buf) { Anope::string newbuf; for (size_t idx = 0; idx < buf.length(); )