summaryrefslogtreecommitdiff
path: root/src/hashcomp.cpp
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/hashcomp.cpp
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/hashcomp.cpp')
-rw-r--r--src/hashcomp.cpp14
1 files changed, 7 insertions, 7 deletions
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();
}