]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
New helper class irc::stringjoiner - it pwns you.
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 3 Oct 2006 13:46:28 +0000 (13:46 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 3 Oct 2006 13:46:28 +0000 (13:46 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5403 e03df62e-2008-0410-955e-edbf42e46eb7

include/hashcomp.h
src/hashcomp.cpp
src/modules/m_remove.cpp
src/modules/m_saquit.cpp

index f4b690caf4a9991245374b9a2f07bcfa4ad1538a..a99b5e76bc9f4920d17b8721fbde8984649a8371 100644 (file)
@@ -123,6 +123,29 @@ namespace irc
                bool operator()(const insp_inaddr &s1, const insp_inaddr &s2) const;
        };
 
+       /** irc::stringjoiner joins string lists into a string, using
+        * the given seperator string.
+        */
+       class stringjoiner
+       {
+        private:
+               std::string joined;
+        public:
+               /** Join elements of a vector, between (and including) begin and end
+                */
+               stringjoiner(const std::string &seperator, const std::vector<std::string> &sequence, int begin, int end);
+               /** Join elements of a deque, between (and including) begin and end
+                */
+               stringjoiner(const std::string &seperator, const std::deque<std::string> &sequence, int begin, int end);
+               /** Join elements of an array of char arrays, between (and including) begin and end
+                */
+               stringjoiner(const std::string &seperator, const char** sequence, int begin, int end);
+
+               /** Get the joined sequence
+                */
+               std::string& GetJoined();
+       };
+
        /** irc::modestacker stacks mode sequences into a list.
         * It can then reproduce this list, clamped to a maximum of MAXMODES
         * values per line.
index 2acd59f9196b95627b87ac3d1437b5faebd2fac3..0908e41b5a318d52c46925b953b44c4e945173a1 100644 (file)
@@ -354,3 +354,30 @@ int irc::modestacker::GetStackedLine(std::deque<std::string> &result)
 
        return n;
 }
+
+irc::stringjoiner::stringjoiner(const std::string &seperator, const std::vector<std::string> &sequence, int begin, int end)
+{
+       for (int v = begin; v < end; v++)
+               joined.append(sequence[v]).append(seperator);
+       joined.append(sequence[end]);
+}
+
+irc::stringjoiner::stringjoiner(const std::string &seperator, const std::deque<std::string> &sequence, int begin, int end)
+{
+       for (int v = begin; v < end; v++)
+               joined.append(sequence[v]).append(seperator);
+       joined.append(sequence[end]);
+}
+
+irc::stringjoiner::stringjoiner(const std::string &seperator, const char** sequence, int begin, int end)
+{
+       for (int v = begin; v < end; v++)
+               joined.append(sequence[v]).append(seperator);
+       joined.append(sequence[end]);
+}
+
+std::string& irc::stringjoiner::GetJoined()
+{
+       return joined;
+}
+
index 83953048730e8b2f9a625fad2942fe5bff0cdd0a..be4292e56369dcf821aebadc181843420cd96fb5 100644 (file)
@@ -48,7 +48,8 @@ class RemoveBase
        enum ModeLevel { PEON = 0, HALFOP = 1, OP = 2, ADMIN = 3, OWNER = 4, ULINE = 5 };        
  
        /* This little function just converts a chanmode character (U ~ & @ & +) into an integer (5 4 3 2 1 0) */
-       /* XXX - this could be handy in the core, so it can be used elsewhere */
+       /* XXX - We should probably use the new mode prefix rank stuff
+        * for this instead now -- Brain */
        ModeLevel chartolevel(const std::string &privs)
        {
                if(privs.empty())
@@ -180,20 +181,16 @@ class RemoveBase
                        if ((ulevel > PEON) && (ulevel >= tlevel) && (tlevel != OWNER))
                        {
                                // no you can't just go from a std::ostringstream to a std::string, Om. -nenolod
-                               std::ostringstream reason_stream;
-                               std::string reasonparam;
+                               // but you can do this, nenolod -brain
+
+                               std::string reasonparam("No reason given");
                                
                                /* If a reason is given, use it */
                                if(pcnt > 2)
                                {
-                                       /* Use all the remaining parameters as the reason */
-                                       for(int i = 2; i < pcnt; i++)
-                                       {
-                                               reason_stream << " " << parameters[i];
-                                       }
-                                       
-                                       reasonparam = reason_stream.str();
-                                       reason_stream.clear();
+                                       /* Join params 2 ... pcnt - 1 (inclusive) into one */
+                                       irc::stringjoiner reason_join(" ", parameters, 2, pcnt - 1);
+                                       reasonparam = reason_join.GetJoined();
                                }
 
                                /* Build up the part reason string. */
index 54eaf7ea81e147bdf5e223309568f41cde2ed5b1..20ffdd99eb0b5f8d7d738f7fa85e69a725b4e0b1 100644 (file)
@@ -57,13 +57,9 @@ class cmd_saquit : public command_t
                                user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
                                return CMD_FAILURE;
                        }
-                       std::string line = "";
-                       for (int i = 1; i < pcnt - 1; i++)
-                       {
-                               line = line + std::string(parameters[i]) + " ";
-                       }
-                       line = line + std::string(parameters[pcnt-1]);
-               
+                       irc::stringjoiner reason_join(" ", parameters, 1, pcnt - 1);
+                       std::string line = reason_join.GetJoined();
+
                        ServerInstance->WriteOpers(std::string(user->nick)+" used SAQUIT to make "+std::string(dest->nick)+" quit with a reason of "+line);
                        userrec::QuitUser(ServerInstance, dest, line);