/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLUtils/src/ICLUtils/StrTok.h ** ** Module : ICLUtils ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #pragma once #include #include #include namespace icl{ namespace utils{ /// String Tokenizer Utility class \ingroup UTILS class ICLUtils_API StrTok{ public: /// Constructor /** @param s string to be tokenized @param delims delimiter string: meaning depends on singleCharDelims @param singleCharDelims if this is true (default), each character of delims is treated a single possible delimiter. Otherwise, the delims string is used as a delimiter sequence @param escapeChar if this char is not '\\0', delimiter occurences are skipped, if this char is found directly before the delimiter. (Often the '\\' char is used here) */ StrTok(const std::string &s,const std::string &delims, bool singleCharDelims=true, char escapeChar='\0'); /// Returns whether more tokens are available using nextToken() /** note: nextToken is not safe; it must be checked with hasMoreTokens */ bool hasMoreTokens() const; /// Returns the next token (unsafe -> check with hasMoreTokens before) const std::string &nextToken(); /// returns the internal token count unsigned int nTokens() const; /// returns a vector const std::vector &allTokens() const; /// resets internal position indicator void reset() { m_uiPos = 0; } /// reverse iterator type typedef std::vector::reverse_iterator reverse_iterator; /// constant reverse iterator type typedef std::vector::const_reverse_iterator const_reverse_iterator; /// iterator type typedef std::vector::iterator iterator; /// constant iterator type typedef std::vector::const_iterator const_iterator; /// returns begin-iterator inline iterator begin() { return m_oTokens.begin(); } /// returns const begin-iterator inline const_iterator begin() const { return m_oTokens.begin(); } /// returns reverse begin-iterator inline reverse_iterator rbegin() { return m_oTokens.rbegin(); } /// returns const reverse begin-iterator inline const_reverse_iterator rbegin() const { return m_oTokens.rbegin(); } /// returns end-iterator inline iterator end() { return m_oTokens.end(); } /// returns const end-iterator inline const_iterator end() const { return m_oTokens.end(); } /// returns reverse end-iterator inline reverse_iterator rend() { return m_oTokens.rend(); } /// returns const reverse end-iterator inline const_reverse_iterator rend() const { return m_oTokens.rend(); } private: /// internal data storage std::vector m_oTokens; /// current position indicator unsigned int m_uiPos; }; } // namespace utils }