]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Convert irc::stringjoiner to be a method instead of a class.
authorPeter Powell <petpow@saberuk.com>
Wed, 5 Feb 2014 16:44:22 +0000 (16:44 +0000)
committerAttila Molnar <attilamolnar@hush.com>
Thu, 6 Feb 2014 22:11:51 +0000 (23:11 +0100)
Add separator parameter

include/hashcomp.h
src/hashcomp.cpp
src/modules/m_cap.cpp
src/modules/m_operlog.cpp
src/modules/m_spanningtree/capab.cpp
src/modules/m_spanningtree/treesocket2.cpp

index de556f39316cf93216577eed69109bf50a3a9f92..6cd3fc3c0fd06f6d7cb67c39ca0011433dbd1a60 100644 (file)
@@ -168,31 +168,11 @@ namespace irc
         */
        typedef std::basic_string<char, irc_char_traits, std::allocator<char> > string;
 
-       /** irc::stringjoiner joins string lists into a string, using
-        * space as the separator.
-        * This class can join a vector of std::string.
+       /** Joins the contents of a vector to a string.
+        * @param sequence Zero or more items to join.
+        * @separator The character to place between the items.
         */
-       class CoreExport stringjoiner
-       {
-        private:
-
-               /** Output string
-                */
-               std::string joined;
-
-        public:
-
-               /** Join all elements of a vector, in the resulting string
-                * each element will be seperated by a single space character.
-                * @param sequence Zero or more items to seperate
-                */
-               stringjoiner(const std::vector<std::string>& sequence);
-
-               /** Get the joined sequence
-                * @return A constant reference to the joined string
-                */
-               const std::string& GetJoined() const { return joined; }
-       };
+       std::string CoreExport stringjoiner(const std::vector<std::string>& sequence, char separator = ' ');
 
        /** irc::modestacker stacks mode sequences into a list.
         * It can then reproduce this list, clamped to a maximum of MAXMODES
index f1d0f0678c739a27afb6c16f86fce149968750c7..32f74475fd632e72ef222ff7967ff2ae7c95bc6e 100644 (file)
@@ -414,14 +414,16 @@ int irc::modestacker::GetStackedLine(std::vector<std::string> &result, int max_l
        return n;
 }
 
-irc::stringjoiner::stringjoiner(const std::vector<std::string>& sequence)
+std::string irc::stringjoiner(const std::vector<std::string>& sequence, char separator)
 {
+       std::string joined;
        if (sequence.empty())
-               return; // nothing to do here
+               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(' ');
+               joined.append(*i).push_back(separator);
        joined.erase(joined.end()-1);
+       return joined;
 }
 
 irc::portparser::portparser(const std::string &source, bool allow_overlapped)
index 9e074b21947fc1d05a929933d5bc451a2f191df0..bc79e59ecae6e832b096013a1e17fac190fd3f5e 100644 (file)
@@ -74,13 +74,13 @@ class CommandCAP : public Command
 
                        if (Data.ack.size() > 0)
                        {
-                               std::string AckResult = irc::stringjoiner(Data.ack).GetJoined();
+                               std::string AckResult = irc::stringjoiner(Data.ack);
                                user->WriteCommand("CAP", "ACK :" + AckResult);
                        }
 
                        if (Data.wanted.size() > 0)
                        {
-                               std::string NakResult = irc::stringjoiner(Data.wanted).GetJoined();
+                               std::string NakResult = irc::stringjoiner(Data.wanted);
                                user->WriteCommand("CAP", "NAK :" + NakResult);
                        }
                }
@@ -95,7 +95,7 @@ class CommandCAP : public Command
                        reghold.set(user, 1);
                        Data.Send();
 
-                       std::string Result = irc::stringjoiner(Data.wanted).GetJoined();
+                       std::string Result = irc::stringjoiner(Data.wanted);
                        user->WriteCommand("CAP", subcommand + " :" + Result);
                }
                else if (subcommand == "CLEAR")
@@ -105,7 +105,7 @@ class CommandCAP : public Command
                        reghold.set(user, 1);
                        Data.Send();
 
-                       std::string Result = irc::stringjoiner(Data.ack).GetJoined();
+                       std::string Result = irc::stringjoiner(Data.ack);
                        user->WriteCommand("CAP", "ACK :" + Result);
                }
                else
index 0da0c1f2099b836f0ccf88cf3a8abf4862a319c3..e89dda7b572aa1254fb88c61763a11060297a078 100644 (file)
@@ -52,8 +52,7 @@ class ModuleOperLog : public Module
                        Command* thiscommand = ServerInstance->Parser->GetHandler(command);
                        if ((thiscommand) && (thiscommand->flags_needed == 'o'))
                        {
-                               std::string line = irc::stringjoiner(parameters).GetJoined();
-                               std::string msg = "[" + user->GetFullRealHost() + "] " + command + " " + line;
+                               std::string msg = "[" + user->GetFullRealHost() + "] " + command + " " + irc::stringjoiner(parameters);
                                ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "OPERLOG: " + msg);
                                if (tosnomask)
                                        ServerInstance->SNO->WriteGlobalSno('r', msg);
index 07d11ad8328822e7286739f27007c4ccc1b66881..c52dffa4124d1f29a85365b1a0d0e3a6524d18e0 100644 (file)
@@ -70,8 +70,7 @@ static std::string BuildModeList(ModeType type)
                }
        }
        sort(modes.begin(), modes.end());
-       irc::stringjoiner line(modes);
-       return line.GetJoined();
+       return irc::stringjoiner(modes);
 }
 
 void TreeSocket::SendCapabilities(int phase)
index f97ce55397f00cd16ba1f111493e94f5ddf50726..4639a237ede4f329a5f4a2ed9f6a475c27330928 100644 (file)
@@ -313,9 +313,8 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                                return;
                        }
 
-                       irc::stringjoiner pmlist(params);
                        ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Unrecognised S2S command :%s %s %s",
-                               who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
+                               who->uuid.c_str(), command.c_str(), irc::stringjoiner(params).c_str());
                        SendError("Unrecognised command '" + command + "' -- possibly loaded mismatched modules");
                        return;
                }
@@ -324,9 +323,8 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
 
        if (params.size() < cmdbase->min_params)
        {
-               irc::stringjoiner pmlist(params);
                ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Insufficient parameters for S2S command :%s %s %s",
-                       who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
+                       who->uuid.c_str(), command.c_str(), irc::stringjoiner(params).c_str());
                SendError("Insufficient parameters for command '" + command + "'");
                return;
        }
@@ -347,9 +345,8 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
 
        if (res == CMD_INVALID)
        {
-               irc::stringjoiner pmlist(params);
                ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Error handling S2S command :%s %s %s",
-                       who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
+                       who->uuid.c_str(), command.c_str(), irc::stringjoiner(params).c_str());
                SendError("Error handling '" + command + "' -- possibly loaded mismatched modules");
        }
        else if (res == CMD_SUCCESS)