00001 // /////////////////////////////////////////////////////////////////////////// 00002 // xrb_tokenizer.hpp by Victor Dods, created 2005/05/01 00003 // /////////////////////////////////////////////////////////////////////////// 00004 // Unless a different license was explicitly granted in writing by the 00005 // copyright holder (Victor Dods), this software is freely distributable under 00006 // the terms of the GNU General Public License, version 2. Any works deriving 00007 // from this work must also be released under the GNU GPL. See the included 00008 // file LICENSE for details. 00009 // /////////////////////////////////////////////////////////////////////////// 00010 00011 #if !defined(_XRB_TOKENIZER_HPP_) 00012 #define _XRB_TOKENIZER_HPP_ 00013 00014 #include "xrb.hpp" 00015 00016 namespace Xrb 00017 { 00018 00019 class Tokenizer 00020 { 00021 public: 00022 00023 // this version of the constructor takes a pointer to a non-const char 00024 // string, which we will use directly. 00025 Tokenizer (char *string_to_tokenize, char const *delimiters); 00026 // this version of the constructor takes a pointer to a const char 00027 // string, which means we will need to make a copy in order to use it. 00028 Tokenizer (const char *string_to_tokenize, char const *delimiters); 00029 // destructor -- deletes the string_to_tokenize iff a copy was made 00030 // of the original. 00031 ~Tokenizer (); 00032 00033 // returns the first token and then successive tokens. 00034 char const *GetToken () const; 00035 00036 private: 00037 00038 // helper function which returns true iff the given character is 00039 // in the set of delimiters. 00040 bool IsCharADelimiter (char c) const; 00041 00042 // the string which will be tokenized. must point to non-const 00043 // chars, because null chars are inserted and removed to delimit 00044 // the end of tokens. 00045 char *m_string_to_tokenize; 00046 // indicates if m_string_to_tokenize is actually an allocated 00047 // copy of the provided string (which means that it will have to 00048 // be deleted upon destruction). 00049 bool m_string_to_tokenize_requires_deletion; 00050 // string containing the delimiters. this string should be immutable, 00051 // or at least exist for the entire life of this Tokenizer object. 00052 // a delimiter cannot be the null char. 00053 char const *m_delimiters; 00054 // a pointer to the end of the last token, where the replaced 00055 // delimiter should be put back. 00056 mutable char *m_end_of_token; 00057 // delimiter which was replaced by a null char in the previous call 00058 // which needs to be replaced to reconstruct the string properly. 00059 mutable char m_replaced_delimiter; 00060 }; // end of class Tokenizer 00061 00062 } // end of namespace Xrb 00063 00064 #endif // !defined(_XRB_TOKENIZER_HPP_)