summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/anope.h5
-rw-r--r--src/command.cpp2
-rw-r--r--src/hashcomp.cpp14
-rw-r--r--src/users.cpp2
4 files changed, 13 insertions, 10 deletions
diff --git a/include/anope.h b/include/anope.h
index 90c0e4c36..03bb2418d 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -554,10 +554,13 @@ class CoreExport sepstream
/** Current string position
*/
size_t pos;
+ /** If set then GetToken() can return an empty string
+ */
+ bool allow_empty;
public:
/** Create a sepstream and fill it with the provided data
*/
- sepstream(const Anope::string &source, char seperator);
+ sepstream(const Anope::string &source, char seperator, bool allowempty = false);
/** Fetch the next token from the stream
* @param token The next token from the stream is placed here
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"))))