diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-10-02 08:47:14 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-10-02 08:47:14 +0000 |
commit | 02fe4a30856a7bc931e680e8667ab9fa13149b15 (patch) | |
tree | 44416f1668b4276c3d62426b9f33a41cf5bb85ec | |
parent | 8b9664a6af2edaa3a51dacb9fb5cfca178241289 (diff) |
modestacker class, stacks modes and returns a string list of up to MAXMODES modes
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5389 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/hashcomp.h | 11 | ||||
-rw-r--r-- | src/hashcomp.cpp | 28 |
2 files changed, 39 insertions, 0 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h index 69fa677b8..dde123acb 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -123,6 +123,17 @@ namespace irc bool operator()(const insp_inaddr &s1, const insp_inaddr &s2) const; }; + class modestacker + { + private: + std::deque<std::string> sequence; + bool adding; + public: + modestacker(bool add); + void Push(char modeletter, const std::string ¶meter); + std::deque<std::string> GetStackedLine(); + }; + /** 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. diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 7eb7075c7..d0a4ab104 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -309,3 +309,31 @@ const char* irc::Spacify(char* n) } +irc::modestacker::modestacker(bool add) : adding(add) +{ + sequence.clear(); + sequence.push_back(""); +} + +void irc::modestacker::Push(char modeletter, const std::string ¶meter) +{ + *(sequence.begin()) += modeletter; + sequence.push_back(parameter); +} + +std::deque<std::string> irc::modestacker::GetStackedLine() +{ + std::deque<std::string> result; + result.push_back(""); + + while (!sequence[0].empty() && (sequence.size() > 1)) + { + result[0] += *(sequence[0].begin()); + result.push_back(sequence[1]); + sequence[0].erase(sequence[0].begin()); + sequence.erase(sequence.begin() + 1); + } + + return result; +} + |