summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-05-05 01:18:16 -0400
committerAdam <Adam@anope.org>2013-05-05 02:00:33 -0400
commite91de41278ff5993973999e4e5095360612ec056 (patch)
tree9945adf89c708406b49b1e4651232c5994c0215a /src
parent10b5b00db4f6f38f33b122f1a2cbcb788fc7c0eb (diff)
Add an option to sepstream to allow it to return empty tokens if multiple separators are found in a row
Diffstat (limited to 'src')
-rw-r--r--src/command.cpp2
-rw-r--r--src/hashcomp.cpp14
-rw-r--r--src/users.cpp2
3 files changed, 9 insertions, 9 deletions
diff --git a/src/command.cpp b/src/command.cpp
index db4bb9996..b7289b848 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -112,7 +112,7 @@ void CommandSource::Reply(const Anope::string &message)
{
const char *translated_message = Language::Translate(this->nc, message.c_str());
- sepstream sep(translated_message, '\n');
+ sepstream sep(translated_message, '\n', true);
Anope::string tok;
while (sep.GetToken(tok))
this->reply->SendMessage(this->service, tok);
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index aac381c9b..3c6430330 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -92,28 +92,28 @@ bool ci::less::operator()(const Anope::string &s1, const Anope::string &s2) cons
return s1.ci_str().compare(s2.ci_str()) < 0;
}
-sepstream::sepstream(const Anope::string &source, char seperator) : tokens(source), sep(seperator), pos(0)
+sepstream::sepstream(const Anope::string &source, char seperator, bool ae) : tokens(source), sep(seperator), pos(0), allow_empty(ae)
{
}
bool sepstream::GetToken(Anope::string &token)
{
- size_t p = this->pos;
-
- while (p < this->tokens.length() && this->tokens[p] == this->sep)
- ++p;
-
if (this->StreamEnd())
{
token.clear();
return false;
}
+ size_t p = this->pos;
while (p < this->tokens.length() && this->tokens[p] != this->sep)
++p;
token = this->tokens.substr(this->pos, p - this->pos);
this->pos = p + 1;
+
+ if (!this->allow_empty && token.empty())
+ return GetToken(token);
+
return true;
}
@@ -152,6 +152,6 @@ const Anope::string sepstream::GetRemaining()
bool sepstream::StreamEnd()
{
- return this->pos >= this->tokens.length();
+ return this->pos > this->tokens.length();
}
diff --git a/src/users.cpp b/src/users.cpp
index 26d5b31c5..61d27deb1 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -278,7 +278,7 @@ void User::SendMessage(const BotInfo *source, const Anope::string &msg)
* - The user is not registered and NSDefMsg is enabled
* - The user is registered and has set /ns set msg on
*/
- sepstream sep(translated_message, '\n');
+ sepstream sep(translated_message, '\n', true);
for (Anope::string tok; sep.GetToken(tok);)
{
if (Config->UsePrivmsg && ((!this->nc && Config->DefPrivmsg) || (this->nc && this->nc->HasExt("MSG"))))