summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/hashcomp.h7
-rw-r--r--include/inspircd.h2
-rw-r--r--include/stdalgo.h19
-rw-r--r--src/hashcomp.cpp12
-rw-r--r--src/inspstring.cpp8
-rw-r--r--src/modules/m_operlog.cpp2
-rw-r--r--src/modules/m_samode.cpp2
-rw-r--r--src/modules/m_spanningtree/capab.cpp2
8 files changed, 25 insertions, 29 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h
index bda85182f..71f900654 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -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
diff --git a/include/inspircd.h b/include/inspircd.h
index 7180fd672..00093e52b 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -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"
diff --git a/include/stdalgo.h b/include/stdalgo.h
index f4465963a..bb5e12262 100644
--- a/include/stdalgo.h
+++ b/include/stdalgo.h
@@ -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
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index 08ce154e8..2288a227e 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -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)
{
diff --git a/src/inspstring.cpp b/src/inspstring.cpp
index 283c00d5b..79aef52bd 100644
--- a/src/inspstring.cpp
+++ b/src/inspstring.cpp
@@ -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;
}
diff --git a/src/modules/m_operlog.cpp b/src/modules/m_operlog.cpp
index 49d816fa9..53bc247be 100644
--- a/src/modules/m_operlog.cpp
+++ b/src/modules/m_operlog.cpp
@@ -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);
diff --git a/src/modules/m_samode.cpp b/src/modules/m_samode.cpp
index e4b102b92..195b767ab 100644
--- a/src/modules/m_samode.cpp
+++ b/src/modules/m_samode.cpp
@@ -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;
diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp
index 79019b668..97b4a90af 100644
--- a/src/modules/m_spanningtree/capab.cpp
+++ b/src/modules/m_spanningtree/capab.cpp
@@ -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)