summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/hashcomp.h25
-rw-r--r--src/hashcomp.cpp10
2 files changed, 26 insertions, 9 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h
index 0a39deb1f..69fa677b8 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -161,22 +161,39 @@ namespace irc
* the next token, until none remain, at which point the method returns
* an empty string.
*/
- class commasepstream
+ class sepstream : public classbase
{
private:
std::string tokens;
std::string::iterator last_starting_position;
std::string::iterator n;
+ char sep;
public:
/** Create a commasepstream and fill it with the provided data
*/
- commasepstream(const std::string &source);
- ~commasepstream();
+ sepstream(const std::string &source, char seperator);
+ virtual ~sepstream();
/** Fetch the next token from the stream
* @returns The next token is returned, or an empty string if none remain
*/
- const std::string GetToken();
+ virtual const std::string GetToken();
+ };
+
+ class commasepstream : public sepstream
+ {
+ public:
+ commasepstream(const std::string &source) : sepstream(source, ',')
+ {
+ }
+ };
+
+ class spacesepstream : public sepstream
+ {
+ public:
+ spacesepstream(const std::string &source) : sepstream(source, ' ')
+ {
+ }
};
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index 8d19d059a..33dcea307 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -248,24 +248,24 @@ const std::string irc::tokenstream::GetToken()
return "";
}
-irc::commasepstream::commasepstream(const std::string &source) : tokens(source)
+irc::sepstream::sepstream(const std::string &source, char seperator) : tokens(source), sep(seperator)
{
last_starting_position = tokens.begin();
n = tokens.begin();
}
-const std::string irc::commasepstream::GetToken()
+const std::string irc::sepstream::GetToken()
{
std::string::iterator lsp = last_starting_position;
while (n != tokens.end())
{
- if ((*n == ',') || (n+1 == tokens.end()))
+ if ((*n == sep) || (n+1 == tokens.end()))
{
last_starting_position = n+1;
std::string strip = std::string(lsp, n+1 == tokens.end() ? n+1 : n++);
- while ((strip.length()) && (strip.find_last_of(',') == strip.length() - 1))
+ while ((strip.length()) && (strip.find_last_of(sep) == strip.length() - 1))
strip.erase(strip.end() - 1);
return strip;
@@ -277,7 +277,7 @@ const std::string irc::commasepstream::GetToken()
return "";
}
-irc::commasepstream::~commasepstream()
+irc::sepstream::~sepstream()
{
}