summaryrefslogtreecommitdiff
path: root/include/hashcomp.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-05-26 18:24:53 -0400
committerAdam <Adam@anope.org>2013-06-02 02:45:53 +0200
commit01ac5148e948de53cd708bb28d0fd237263a0fbf (patch)
tree7c2a65f98c2624d0c4f09d9e60c984947e610604 /include/hashcomp.h
parent81fce393e99a940682cf58a1203f4ed03d1887fc (diff)
Rewrote sepstream and tokenstream to be less ugly
Diffstat (limited to 'include/hashcomp.h')
-rw-r--r--include/hashcomp.h124
1 files changed, 53 insertions, 71 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h
index e142dcfd3..0f530e97e 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -264,68 +264,6 @@ namespace irc
};
- /** irc::tokenstream reads a string formatted as per RFC1459 and RFC2812.
- * It will split the string into 'tokens' each containing one parameter
- * from the string.
- * For instance, if it is instantiated with the string:
- * "PRIVMSG #test :foo bar baz qux"
- * then each successive call to tokenstream::GetToken() will return
- * "PRIVMSG", "#test", "foo bar baz qux", "".
- * Note that if the whole string starts with a colon this is not taken
- * to mean the string is all one parameter, and the first item in the
- * list will be ":item". This is to allow for parsing 'source' fields
- * from data.
- */
- class CoreExport tokenstream
- {
- private:
-
- /** Original string
- */
- std::string tokens;
-
- /** Last position of a seperator token
- */
- std::string::iterator last_starting_position;
-
- /** Current string position
- */
- std::string::iterator n;
-
- /** True if the last value was an ending value
- */
- bool last_pushed;
- public:
-
- /** Create a tokenstream and fill it with the provided data
- */
- tokenstream(const std::string &source);
-
- /** Fetch the next token from the stream as a std::string
- * @param token The next token available, or an empty string if none remain
- * @return True if tokens are left to be read, false if the last token was just retrieved.
- */
- bool GetToken(std::string &token);
-
- /** Fetch the next token from the stream as an irc::string
- * @param token The next token available, or an empty string if none remain
- * @return True if tokens are left to be read, false if the last token was just retrieved.
- */
- bool GetToken(irc::string &token);
-
- /** Fetch the next token from the stream as an integer
- * @param token The next token available, or undefined if none remain
- * @return True if tokens are left to be read, false if the last token was just retrieved.
- */
- bool GetToken(int &token);
-
- /** Fetch the next token from the stream as a long integer
- * @param token The next token available, or undefined if none remain
- * @return True if tokens are left to be read, false if the last token was just retrieved.
- */
- bool GetToken(long &token);
- };
-
/** irc::sepstream allows for splitting token seperated lists.
* Each successive call to sepstream::GetToken() returns
* the next token, until none remain, at which point the method returns
@@ -333,23 +271,23 @@ namespace irc
*/
class CoreExport sepstream
{
- private:
+ protected:
/** Original string.
*/
std::string tokens;
- /** Last position of a seperator token
+ /** Separator value
*/
- std::string::iterator last_starting_position;
+ char sep;
/** Current string position
*/
- std::string::iterator n;
- /** Seperator value
+ size_t pos;
+ /** If set then GetToken() can return an empty string
*/
- char sep;
+ bool allow_empty;
public:
/** Create a sepstream and fill it with the provided data
*/
- sepstream(const std::string &source, char seperator);
+ sepstream(const std::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
@@ -375,7 +313,7 @@ namespace irc
public:
/** Initialize with comma seperator
*/
- commasepstream(const std::string &source) : sepstream(source, ',')
+ commasepstream(const std::string &source, bool allowempty = false) : sepstream(source, ',', allowempty)
{
}
};
@@ -387,11 +325,55 @@ namespace irc
public:
/** Initialize with space seperator
*/
- spacesepstream(const std::string &source) : sepstream(source, ' ')
+ spacesepstream(const std::string &source, bool allowempty = false) : sepstream(source, ' ', allowempty)
{
}
};
+ /** irc::tokenstream reads a string formatted as per RFC1459 and RFC2812.
+ * It will split the string into 'tokens' each containing one parameter
+ * from the string.
+ * For instance, if it is instantiated with the string:
+ * "PRIVMSG #test :foo bar baz qux"
+ * then each successive call to tokenstream::GetToken() will return
+ * "PRIVMSG", "#test", "foo bar baz qux", "".
+ * Note that if the whole string starts with a colon this is not taken
+ * to mean the string is all one parameter, and the first item in the
+ * list will be ":item". This is to allow for parsing 'source' fields
+ * from data.
+ */
+ class CoreExport tokenstream : private spacesepstream
+ {
+ public:
+ /** Create a tokenstream and fill it with the provided data
+ */
+ tokenstream(const std::string &source);
+
+ /** Fetch the next token from the stream as a std::string
+ * @param token The next token available, or an empty string if none remain
+ * @return True if tokens are left to be read, false if the last token was just retrieved.
+ */
+ bool GetToken(std::string &token);
+
+ /** Fetch the next token from the stream as an irc::string
+ * @param token The next token available, or an empty string if none remain
+ * @return True if tokens are left to be read, false if the last token was just retrieved.
+ */
+ bool GetToken(irc::string &token);
+
+ /** Fetch the next token from the stream as an integer
+ * @param token The next token available, or undefined if none remain
+ * @return True if tokens are left to be read, false if the last token was just retrieved.
+ */
+ bool GetToken(int &token);
+
+ /** Fetch the next token from the stream as a long integer
+ * @param token The next token available, or undefined if none remain
+ * @return True if tokens are left to be read, false if the last token was just retrieved.
+ */
+ bool GetToken(long &token);
+ };
+
/** The portparser class seperates out a port range into integers.
* A port range may be specified in the input string in the form
* "6660,6661,6662-6669,7020". The end of the stream is indicated by