diff options
author | Joe Zhao <ztuowen@gmail.com> | 2014-04-14 08:14:45 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2014-04-14 08:14:45 +0800 |
commit | cccccbf6cca94a3eaf813b4468453160e91c332b (patch) | |
tree | 23418cb73a10ae3b0688681a7f0ba9b06424583e /src/KaldiLib/Tokenizer.h | |
download | tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.gz tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.bz2 tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.zip |
First commit
Diffstat (limited to 'src/KaldiLib/Tokenizer.h')
-rw-r--r-- | src/KaldiLib/Tokenizer.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/KaldiLib/Tokenizer.h b/src/KaldiLib/Tokenizer.h new file mode 100644 index 0000000..1be717b --- /dev/null +++ b/src/KaldiLib/Tokenizer.h @@ -0,0 +1,45 @@ +#include <list> +#include <string> + +namespace TNet { + /** + * @brief General string tokenizer + */ + class Tokenizer + : public std::list<std::string> + { + public: + // Constructors and Destructors ............................................ + Tokenizer(const char* pSeparator, bool skipEmpty = false) + : std::list<std::string>(), mSeparator(pSeparator), mSkipEmpty(skipEmpty) + {} + + Tokenizer(const char* pString, const char* pSeparator, bool skipEmpty = false) + : std::list<std::string>(), mSeparator(pSeparator), mSkipEmpty(skipEmpty) + { AddString(pString); } + + ~Tokenizer() + {} + + /** + * @brief Parses a string and appends the tokens to the list + * @param pString string to parse + */ + void + AddString(const char* pString); + + /** + * @brief Constant accessor to the separators string + * @return Const refference + */ + const std::string& + Separator() const + {return mSeparator;} + + private: + std::string mSeparator; ///< holds the list of separators + bool mSkipEmpty; ///< if true, multiple separators will be regarded as one + }; // class Tokenizer +} // namespace TNet + + |