From c77cc4f737c782c3a56d69da0eac82edd41d4976 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 11 Feb 2014 14:08:11 +0100 Subject: m_operjoin Remove duplicated code --- src/modules/m_operjoin.cpp | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/modules/m_operjoin.cpp b/src/modules/m_operjoin.cpp index 8a5041190..dd80d99ba 100644 --- a/src/modules/m_operjoin.cpp +++ b/src/modules/m_operjoin.cpp @@ -26,39 +26,20 @@ class ModuleOperjoin : public Module { - std::string operChan; std::vector operChans; bool override; - int tokenize(const std::string &str, std::vector &tokens) - { - // skip delimiters at beginning. - std::string::size_type lastPos = str.find_first_not_of(",", 0); - // find first "non-delimiter". - std::string::size_type pos = str.find_first_of(",", lastPos); - - while (std::string::npos != pos || std::string::npos != lastPos) - { - // found a token, add it to the vector. - tokens.push_back(str.substr(lastPos, pos - lastPos)); - // skip delimiters. Note the "not_of" - lastPos = str.find_first_not_of(",", pos); - // find next "non-delimiter" - pos = str.find_first_of(",", lastPos); - } - return tokens.size(); - } - public: void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* tag = ServerInstance->Config->ConfValue("operjoin"); - operChan = tag->getString("channel"); override = tag->getBool("override", false); + irc::commasepstream ss(tag->getString("channel")); operChans.clear(); - if (!operChan.empty()) - tokenize(operChan,operChans); + + for (std::string channame; ss.GetToken(channame); ) + operChans.push_back(channame); } Version GetVersion() CXX11_OVERRIDE @@ -76,18 +57,11 @@ class ModuleOperjoin : public Module if (ServerInstance->IsChannel(*i)) Channel::JoinUser(localuser, *i, override); - std::string chanList = localuser->oper->getConfig("autojoin"); - if (!chanList.empty()) + irc::commasepstream ss(localuser->oper->getConfig("autojoin")); + for (std::string channame; ss.GetToken(channame); ) { - std::vector typechans; - tokenize(chanList, typechans); - for (std::vector::const_iterator it = typechans.begin(); it != typechans.end(); ++it) - { - if (ServerInstance->IsChannel(*it)) - { - Channel::JoinUser(localuser, *it, override); - } - } + if (ServerInstance->IsChannel(channame)) + Channel::JoinUser(localuser, channame, override); } } }; -- cgit v1.2.3