]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Replace irc::stringjoiner with a generic stdalgo::string::join.
authorPeter Powell <petpow@saberuk.com>
Thu, 26 Jul 2018 20:23:45 +0000 (21:23 +0100)
committerPeter Powell <petpow@saberuk.com>
Thu, 26 Jul 2018 20:41:36 +0000 (21:41 +0100)
This can also be used with different types of collection containing
values which are not a string.

include/hashcomp.h
include/inspircd.h
include/stdalgo.h
src/hashcomp.cpp
src/inspstring.cpp
src/modules/m_operlog.cpp
src/modules/m_samode.cpp
src/modules/m_spanningtree/capab.cpp

index bda85182f2bd26463d5c998f0ed8d4c74ef7f855..71f900654bfc12a3f587db36726f949387a47de4 100644 (file)
@@ -108,13 +108,6 @@ namespace irc
                bool CoreExport operator()(const std::string& a, const std::string& b) const;
        };
 
-       /** Joins the contents of a vector to a string.
-        * @param sequence Zero or more items to join.
-        * @param separator The character to place between the items, defaults to ' ' (space).
-        * @return Joined string.
-        */
-       std::string CoreExport stringjoiner(const std::vector<std::string>& sequence, char separator = ' ');
-
        /** irc::sepstream allows for splitting token seperated lists.
         * Each successive call to sepstream::GetToken() returns
         * the next token, until none remain, at which point the method returns
index 7180fd672028fbc8b0b8b3656f9c7296a736d4ec..00093e52ba07fbbd33f0ef3d79fd87f7fd3b3fed 100644 (file)
@@ -50,6 +50,7 @@
 #include "compat.h"
 #include "aligned_storage.h"
 #include "typedefs.h"
+#include "convto.h"
 #include "stdalgo.h"
 
 CoreExport extern InspIRCd* ServerInstance;
@@ -66,7 +67,6 @@ struct fakederef
 };
 
 #include "config.h"
-#include "convto.h"
 #include "dynref.h"
 #include "consolecolors.h"
 #include "cull_list.h"
index f4465963a65f5bd0884831d647ca5f4ffea65799..bb5e122623277a9daa60a6ecd13a82852db74ed1 100644 (file)
@@ -95,6 +95,25 @@ namespace stdalgo
                        return (!strcasecmp(tocstr(str1), tocstr(str2)));
                }
 
+               /** Joins the contents of a vector to a string.
+                * @param sequence Zero or more items to join.
+                * @param separator The character to place between the items, defaults to ' ' (space).
+                * @return The joined string.
+                */
+               template<typename Collection>
+               inline std::string join(const Collection& sequence, char separator = ' ')
+               {
+                       std::string joined;
+                       if (sequence.empty())
+                               return joined;
+
+                       for (typename Collection::const_iterator iter = sequence.begin(); iter != sequence.end(); ++iter)
+                               joined.append(ConvToStr(*iter)).push_back(separator);
+
+                       joined.erase(joined.end() - 1);
+                       return joined;
+               }
+
                /** Replace first occurrence of a substring ('target') in a string ('str') with another string ('replacement').
                 * @param str String to perform replacement in
                 * @param target String to replace
index 08ce154e81fe38dca1a984ab2dc731bef39c1908..2288a227eb14d4cb6499cb04ad7034c189a57b88 100644 (file)
@@ -279,18 +279,6 @@ bool irc::sepstream::StreamEnd()
        return this->pos > this->tokens.length();
 }
 
-std::string irc::stringjoiner(const std::vector<std::string>& sequence, char separator)
-{
-       std::string joined;
-       if (sequence.empty())
-               return joined; // nothing to do here
-
-       for (std::vector<std::string>::const_iterator i = sequence.begin(); i != sequence.end(); ++i)
-               joined.append(*i).push_back(separator);
-       joined.erase(joined.end()-1);
-       return joined;
-}
-
 irc::portparser::portparser(const std::string &source, bool allow_overlapped)
        : sep(source), in_range(0), range_begin(0), range_end(0), overlapped(allow_overlapped)
 {
index 283c00d5b2fd7cfe458df77000ed55a96aea7597..79aef52bd4dfbdebd7b6f8314a0b1d14c03ef5e3 100644 (file)
@@ -206,12 +206,8 @@ void TokenList::Remove(const std::string& token)
 
 std::string TokenList::ToString() const
 {
-       std::string buffer(permissive ? "*" : "-*");
-       for (insp::flat_set<std::string>::const_iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
-       {
-               buffer.push_back(' ');
-               buffer.append(*iter);
-       }
+       std::string buffer(permissive ? "* " : "-* ");
+       buffer.append(stdalgo::string::join(tokens));
        return buffer;
 }
 
index 49d816fa9243e6da587d039d59bd0a002cc00d09..53bc247be360a55d833aaf1acfe617ec557d31fa 100644 (file)
@@ -52,7 +52,7 @@ class ModuleOperLog : public Module
                        Command* thiscommand = ServerInstance->Parser.GetHandler(command);
                        if ((thiscommand) && (thiscommand->flags_needed == 'o'))
                        {
-                               std::string msg = "[" + user->GetFullRealHost() + "] " + command + " " + irc::stringjoiner(parameters);
+                               std::string msg = "[" + user->GetFullRealHost() + "] " + command + " " + stdalgo::string::join(parameters);
                                ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "OPERLOG: " + msg);
                                if (tosnomask)
                                        ServerInstance->SNO->WriteGlobalSno('r', msg);
index e4b102b92bce13512f8c1730d0df3207148fdd9a..195b767ab462e4c47c828d6bf22cddc224415ac8 100644 (file)
@@ -68,7 +68,7 @@ class CommandSamode : public Command
                        // Viewing the modes of a user or a channel can also result in CMD_SUCCESS, but
                        // that is not possible with /SAMODE because we require at least 2 parameters.
                        const std::string& lastparse = ServerInstance->Modes.GetLastParse();
-                       ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SAMODE: " + (lastparse.empty() ? irc::stringjoiner(parameters) : lastparse));
+                       ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SAMODE: " + (lastparse.empty() ? stdalgo::string::join(parameters) : lastparse));
                }
 
                return CMD_SUCCESS;
index 79019b668308f6c17d27ea79d12677e4324ee148..97b4a90af6bcb8eaf5271680f16547c13996b49d 100644 (file)
@@ -98,7 +98,7 @@ static std::string BuildModeList(ModeType type)
                modes.push_back(mdesc);
        }
        std::sort(modes.begin(), modes.end());
-       return irc::stringjoiner(modes);
+       return stdalgo::string::join(modes);
 }
 
 void TreeSocket::SendCapabilities(int phase)