diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-08 18:48:07 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-08 18:48:07 +0100 |
commit | f713b1d393230e7083727d457623fdac878eb248 (patch) | |
tree | b32d2fb6043b81e3ceb85df808a82ddbe39e59e1 /src | |
parent | 4854509f8add1e2ff167623fb0e8d4216d9d6023 (diff) |
DynamicTokenizer now gets the reader as a parameter to read and peek -- the beauty of this tokenizer is that it has no internal state depending on the reader, so it doesn't need to hold a reference to it
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/plain/DynamicTokenizer.cpp | 35 | ||||
-rw-r--r-- | src/plugins/plain/DynamicTokenizer.hpp | 22 |
2 files changed, 27 insertions, 30 deletions
diff --git a/src/plugins/plain/DynamicTokenizer.cpp b/src/plugins/plain/DynamicTokenizer.cpp index a8f2317..f2cfcd1 100644 --- a/src/plugins/plain/DynamicTokenizer.cpp +++ b/src/plugins/plain/DynamicTokenizer.cpp @@ -345,14 +345,13 @@ public: /* Class DynamicTokenizer */ -DynamicTokenizer::DynamicTokenizer(CharReader &reader, - WhitespaceMode whitespaceMode) - : reader(reader), whitespaceMode(whitespaceMode), nextTokenTypeId(0) +DynamicTokenizer::DynamicTokenizer(WhitespaceMode whitespaceMode) + : whitespaceMode(whitespaceMode), nextTokenTypeId(0) { } template <typename TextHandler, bool read> -bool DynamicTokenizer::next(DynamicToken &token) +bool DynamicTokenizer::next(CharReader &reader, DynamicToken &token) { // If we're in the read mode, reset the char reader peek position to the // current read position @@ -437,28 +436,28 @@ bool DynamicTokenizer::next(DynamicToken &token) return match.hasMatch(); } -bool DynamicTokenizer::read(DynamicToken &token) +bool DynamicTokenizer::read(CharReader &reader,DynamicToken &token) { switch (whitespaceMode) { case WhitespaceMode::PRESERVE: - return next<PreservingTextHandler, true>(token); + return next<PreservingTextHandler, true>(reader, token); case WhitespaceMode::TRIM: - return next<TrimmingTextHandler, true>(token); + return next<TrimmingTextHandler, true>(reader, token); case WhitespaceMode::COLLAPSE: - return next<CollapsingTextHandler, true>(token); + return next<CollapsingTextHandler, true>(reader, token); } return false; } -bool DynamicTokenizer::peek(DynamicToken &token) +bool DynamicTokenizer::peek(CharReader &reader,DynamicToken &token) { switch (whitespaceMode) { case WhitespaceMode::PRESERVE: - return next<PreservingTextHandler, false>(token); + return next<PreservingTextHandler, false>(reader, token); case WhitespaceMode::TRIM: - return next<TrimmingTextHandler, false>(token); + return next<TrimmingTextHandler, false>(reader, token); case WhitespaceMode::COLLAPSE: - return next<CollapsingTextHandler, false>(token); + return next<CollapsingTextHandler, false>(reader, token); } return false; } @@ -530,16 +529,16 @@ WhitespaceMode DynamicTokenizer::getWhitespaceMode() { return whitespaceMode; } /* Explicitly instantiate all possible instantiations of the "next" member function */ template bool DynamicTokenizer::next<PreservingTextHandler, false>( - DynamicToken &token); + CharReader &reader, DynamicToken &token); template bool DynamicTokenizer::next<TrimmingTextHandler, false>( - DynamicToken &token); + CharReader &reader, DynamicToken &token); template bool DynamicTokenizer::next<CollapsingTextHandler, false>( - DynamicToken &token); + CharReader &reader,DynamicToken &token); template bool DynamicTokenizer::next<PreservingTextHandler, true>( - DynamicToken &token); + CharReader &reader,DynamicToken &token); template bool DynamicTokenizer::next<TrimmingTextHandler, true>( - DynamicToken &token); + CharReader &reader,DynamicToken &token); template bool DynamicTokenizer::next<CollapsingTextHandler, true>( - DynamicToken &token); + CharReader &reader,DynamicToken &token); } diff --git a/src/plugins/plain/DynamicTokenizer.hpp b/src/plugins/plain/DynamicTokenizer.hpp index 760bebf..0b4dd39 100644 --- a/src/plugins/plain/DynamicTokenizer.hpp +++ b/src/plugins/plain/DynamicTokenizer.hpp @@ -119,11 +119,6 @@ enum class WhitespaceMode { class DynamicTokenizer { private: /** - * CharReader instance from which the tokens should be read. - */ - CharReader &reader; - - /** * Internally used token trie. This object holds all registered tokens. */ TokenTrie trie; @@ -151,23 +146,22 @@ private: * @tparam TextHandler is the type to be used for the textHandler instance. * @tparam read specifies whether the function should start from and advance * the read pointer of the char reader. + * @param reader is the CharReader instance from which the data should be + * read. * @param token is the token structure into which the token information * should be written. * @return false if the end of the stream has been reached, true otherwise. */ template <typename TextHandler, bool read> - bool next(DynamicToken &token); + bool next(CharReader &reader, DynamicToken &token); public: /** * Constructor of the DynamicTokenizer class. * - * @param reader is the CharReader that should be used for reading the - * tokens. * @param whitespaceMode specifies how whitespace should be handled. */ - DynamicTokenizer(CharReader &reader, - WhitespaceMode whitespaceMode = WhitespaceMode::COLLAPSE); + DynamicTokenizer(WhitespaceMode whitespaceMode = WhitespaceMode::COLLAPSE); /** * Registers the given string as a token. Returns a const pointer at a @@ -222,23 +216,27 @@ public: * Reads a new token from the CharReader and stores it in the given * DynamicToken instance. * + * @param reader is the CharReader instance from which the data should be + * read. * @param token is a reference at the token instance into which the Token * information should be written. * @return true if a token could be read, false if the end of the stream * has been reached. */ - bool read(DynamicToken &token); + bool read(CharReader &reader, DynamicToken &token); /** * The peek method does not advance the read position of the char reader, * but reads the next token from the current char reader peek position. * + * @param reader is the CharReader instance from which the data should be + * read. * @param token is a reference at the token instance into which the Token * information should be written. * @return true if a token could be read, false if the end of the stream * has been reached. */ - bool peek(DynamicToken &token); + bool peek(CharReader &reader, DynamicToken &token); }; } |