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
#include "compat.h"
#include "aligned_storage.h"
#include "typedefs.h"
+#include "convto.h"
#include "stdalgo.h"
CoreExport extern InspIRCd* ServerInstance;
};
#include "config.h"
-#include "convto.h"
#include "dynref.h"
#include "consolecolors.h"
#include "cull_list.h"
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
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)
{
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;
}
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);
// 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;
modes.push_back(mdesc);
}
std::sort(modes.begin(), modes.end());
- return irc::stringjoiner(modes);
+ return stdalgo::string::join(modes);
}
void TreeSocket::SendCapabilities(int phase)