*/
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
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)
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);
}
}
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")
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
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);
}
}
sort(modes.begin(), modes.end());
- irc::stringjoiner line(modes);
- return line.GetJoined();
+ return irc::stringjoiner(modes);
}
void TreeSocket::SendCapabilities(int phase)
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;
}
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;
}
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)