Debian Codegraph @

CodeLite/tokenizer.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2008 by Eran Ifrah
5 // file name : tokenizer.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25 // StringTokenizer.h: interface for the StringTokenizer class.
26 //
27 //////////////////////////////////////////////////////////////////////
28
29 #ifndef CODELITE_TOKENIZER_H
30 #define CODELITE_TOKENIZER_H
31
32 #include <wx/string.h>
33 #include <vector>
34 #include <wx/arrstr.h>
35 #include "codelite_exports.h"
36
37 /**
38 * StringTokenizer helps you to break a string up into a number of tokens.
39 * It replaces the standard C function strtok() and also extends it in a number of ways.
40 *
41 * Usage example:
42 *
43 * \code
44 * StringTokenizer tok(_T("first second third"), _T(" "));
45 * while( tok.HasMore() )
46 * {
47 * wxString token = tok.Next();
48 * }
49 * \endcode
50 *
51 * An alternate way to iterate over the tokenizer:
52 *
53 * \code
54 * StringTokenizer tok(_T("first second third"), _T(" "));
55 * for(int i=0; i<tok.GetCount(); i++)
56 * {
57 * wxString token = tok[i];
58 * }
59 * \endcode
60 *
61 * StringTokenizer also allows you to break string with number of delimiters:
62 *
63 * \code
64 * wxArrayString dlimArr;
65 * delimArr.Add("_T(" "));
66 * delimArr.Add("_T("-"));
67 * delimArr.Add("_T(":"));
68 * StringTokenizer tok(_T("first-second:third"), delimArr);
69 * \endcode
70 *
71 * The above exmple will result with: first, second and third.
72 *
73 * \ingroup CodeLite
74 * \version 1.0
75 * first version
76 *
77 * \date 09-02-2006
78 * \author Eran
79 */
80 class WXDLLIMPEXP_CL StringTokenizer
81 {
82 std::vector<wxString> m_tokensArr;
83 int m_nCurr;
84
85 public:
86 /**
87 * Construct a tokenizer with given input string and delimiter
88 * \param str source string
89 * \param delimiter delimiter to use
90 * \param bAllowEmptyTokens if set to true, empty tokens will be returned as well. Default is no empty tokens
91 */
92 StringTokenizer(const wxString& str,const wxString& delimiter = _T(" ") , const bool &bAllowEmptyTokens = false);
93
94 /**
95 * Construct a tokenizer with given input string and array of delimiters
96 * \param str source string
97 * \param delimiterArr array of delimiters
98 * \param bAllowEmptyTokens if set to true, empty tokens will be returned as well. Default is no empty tokens
99 */
100 StringTokenizer(const wxString& str,const wxArrayString& delimiterArr, const bool &bAllowEmptyTokens = false);
101 /**
102 * Copy constructor
103 * \param src source tokenizer
104 */
105 StringTokenizer(const StringTokenizer& src);
106
107 /**
108 * Default constructor
109 */
110 StringTokenizer(); //Default
111
112 /**
113 * Destructor
114 */
115 virtual ~StringTokenizer();
116
117 //-----------------------------------------------------
118 // Operations
119 //-----------------------------------------------------
120
121 /**
122 * Return the last token
123 * \return last token
124 */
125 wxString Last();
126 /**
127 * Get the number of tokens
128 * \return number of tokens
129 */
130 const int Count() const;
131 /**
132 * Return the current token without progressing the internal pointer
133 * \return current token
134 */
135 wxString Current();
136
137 /**
138 * Return the first token and progress the internal pointer
139 * \return First token
140 */
141 wxString First();
142 /**
143 * Do we have more tokens?
144 * \return true if the next call to Next() will return a token
145 */
146 bool HasMore();
147 /**
148 * Return the previous string, this function moves the internal pointer backward.
149 * So, subsequent calls to this function, will eventually return us to the start of the tokenizer
150 * \return previous token of empty string if we are already at start
151 */
152 wxString Previous();
153 /**
154 * Return next token, usually combined with HasMore() function. This function progress the
155 * internal pointer to next token
156 * \return next token
157 */
158 wxString Next();
159 /**
160 * Random acess operator, statring from zero
161 * \param nIndex token index
162 * \return token at nIndex (copy of it)
163 */
164 wxString operator[](const int nIndex);
165
166 /**
167 * Copy one tokenizer to another
168 * \param src source tokenizer to copy from
169 * \return this
170 */
171 StringTokenizer& operator=(const StringTokenizer& src);
172
173 private:
174 // Functions
175 /**
176 * Initialize the tokenizer
177 */
178 void Initialize();
179 };
180
181 #endif // CODELITE_TOKENIZER_H