<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>GNU CommonC++: tokenizer.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.4.6 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li id="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul></div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul></div> <h1>tokenizer.h</h1><a href="tokenizer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (C) 1999-2005 Open Source Telecom Corporation.</span> <a name="l00002"></a>00002 <span class="comment">//</span> <a name="l00003"></a>00003 <span class="comment">// This program is free software; you can redistribute it and/or modify</span> <a name="l00004"></a>00004 <span class="comment">// it under the terms of the GNU General Public License as published by</span> <a name="l00005"></a>00005 <span class="comment">// the Free Software Foundation; either version 2 of the License, or</span> <a name="l00006"></a>00006 <span class="comment">// (at your option) any later version.</span> <a name="l00007"></a>00007 <span class="comment">// </span> <a name="l00008"></a>00008 <span class="comment">// This program is distributed in the hope that it will be useful,</span> <a name="l00009"></a>00009 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00010"></a>00010 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <a name="l00011"></a>00011 <span class="comment">// GNU General Public License for more details.</span> <a name="l00012"></a>00012 <span class="comment">//</span> <a name="l00013"></a>00013 <span class="comment">// You should have received a copy of the GNU General Public License</span> <a name="l00014"></a>00014 <span class="comment">// along with this program; if not, write to the Free Software</span> <a name="l00015"></a>00015 <span class="comment">// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span> <a name="l00016"></a>00016 <span class="comment">// </span> <a name="l00017"></a>00017 <span class="comment">// As a special exception, you may use this file as part of a free software</span> <a name="l00018"></a>00018 <span class="comment">// library without restriction. Specifically, if other files instantiate</span> <a name="l00019"></a>00019 <span class="comment">// templates or use macros or inline functions from this file, or you compile</span> <a name="l00020"></a>00020 <span class="comment">// this file and link it with other files to produce an executable, this</span> <a name="l00021"></a>00021 <span class="comment">// file does not by itself cause the resulting executable to be covered by</span> <a name="l00022"></a>00022 <span class="comment">// the GNU General Public License. This exception does not however </span> <a name="l00023"></a>00023 <span class="comment">// invalidate any other reasons why the executable file might be covered by</span> <a name="l00024"></a>00024 <span class="comment">// the GNU General Public License. </span> <a name="l00025"></a>00025 <span class="comment">//</span> <a name="l00026"></a>00026 <span class="comment">// This exception applies only to the code released under the name GNU</span> <a name="l00027"></a>00027 <span class="comment">// Common C++. If you copy code from other releases into a copy of GNU</span> <a name="l00028"></a>00028 <span class="comment">// Common C++, as the General Public License permits, the exception does</span> <a name="l00029"></a>00029 <span class="comment">// not apply to the code that you add in this way. To avoid misleading</span> <a name="l00030"></a>00030 <span class="comment">// anyone as to the status of such modified files, you must delete</span> <a name="l00031"></a>00031 <span class="comment">// this exception notice from them.</span> <a name="l00032"></a>00032 <span class="comment">//</span> <a name="l00033"></a>00033 <span class="comment">// If you write modifications of your own for GNU Common C++, it is your choice</span> <a name="l00034"></a>00034 <span class="comment">// whether to permit this exception to apply to your modifications.</span> <a name="l00035"></a>00035 <span class="comment">// If you do not wish that, delete this exception notice.</span> <a name="l00036"></a>00036 <span class="comment">//</span> <a name="l00037"></a>00037 <a name="l00043"></a>00043 <span class="preprocessor">#ifndef CCXX_TOKENIZER_H_</span> <a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#define CCXX_TOKENIZER_H_</span> <a name="l00045"></a>00045 <span class="preprocessor"></span> <a name="l00046"></a>00046 <span class="preprocessor">#ifndef CCXX_MISSING_H_</span> <a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#include <<a class="code" href="missing_8h.html">cc++/missing.h</a>></span> <a name="l00048"></a>00048 <span class="preprocessor">#endif</span> <a name="l00049"></a>00049 <span class="preprocessor"></span> <a name="l00050"></a>00050 <span class="preprocessor">#ifndef CCXX_THREAD_H_</span> <a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#include <<a class="code" href="thread_8h.html">cc++/thread.h</a>></span> <a name="l00052"></a>00052 <span class="preprocessor">#endif</span> <a name="l00053"></a>00053 <span class="preprocessor"></span> <a name="l00054"></a>00054 <span class="preprocessor">#ifdef CCXX_NAMESPACES</span> <a name="l00055"></a>00055 <span class="preprocessor"></span><span class="keyword">namespace </span>ost { <a name="l00056"></a>00056 <span class="preprocessor">#endif</span> <a name="l00057"></a>00057 <span class="preprocessor"></span> <a name="l00101"></a><a class="code" href="classost_1_1_string_tokenizer.html">00101</a> <span class="keyword">class </span><a class="code" href="config_8h.html#d10ef148ba8327bd530fc6c32c1e181c">__EXPORT</a> StringTokenizer { <a name="l00102"></a>00102 <span class="keyword">public</span>: <a name="l00108"></a><a class="code" href="classost_1_1_string_tokenizer.html#4018e923303101ebd6d01cdbca10ce38">00108</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * <span class="keyword">const</span> SPACE; <a name="l00109"></a>00109 <a name="l00119"></a>00119 <span class="comment">// maybe move more global ?</span> <a name="l00120"></a><a class="code" href="classost_1_1_string_tokenizer_1_1_no_such_element_exception.html">00120</a> <span class="keyword">class </span><a class="code" href="classost_1_1_string_tokenizer_1_1_no_such_element_exception.html">NoSuchElementException</a> { }; <a name="l00121"></a>00121 <a name="l00126"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html">00126</a> <span class="keyword">class </span><a class="code" href="config_8h.html#d10ef148ba8327bd530fc6c32c1e181c">__EXPORT</a> iterator { <a name="l00127"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#e4c807aed5a3c9b17fa4b6f44e1f8012">00127</a> <span class="keyword">friend</span> <span class="keyword">class </span>StringTokenizer; <span class="comment">// access our private constructors</span> <a name="l00128"></a>00128 <span class="keyword">private</span>: <a name="l00129"></a>00129 <span class="keyword">const</span> StringTokenizer *myTok; <span class="comment">// my StringTokenizer</span> <a name="l00130"></a>00130 <span class="keyword">const</span> <span class="keywordtype">char</span> *start; <span class="comment">// start of current token</span> <a name="l00131"></a>00131 <span class="keyword">const</span> <span class="keywordtype">char</span> *tokEnd; <span class="comment">// end of current token (->nxDelimiter)</span> <a name="l00132"></a>00132 <span class="keyword">const</span> <span class="keywordtype">char</span> *endp; <span class="comment">// one before next token</span> <a name="l00133"></a>00133 <span class="keywordtype">char</span> *token; <span class="comment">// allocated token, if requested</span> <a name="l00134"></a>00134 <a name="l00135"></a>00135 <span class="comment">// for initialization of the itEnd iterator</span> <a name="l00136"></a>00136 iterator(<span class="keyword">const</span> StringTokenizer &tok, <span class="keyword">const</span> <span class="keywordtype">char</span> *end) <a name="l00137"></a>00137 : myTok(&tok),tokEnd(0),endp(end),token(0) {} <a name="l00138"></a>00138 <a name="l00139"></a>00139 iterator(<span class="keyword">const</span> StringTokenizer &tok) <a name="l00140"></a>00140 : myTok(&tok),tokEnd(0),endp(myTok->str-1),token(0) { <a name="l00141"></a>00141 ++(*this); <span class="comment">// init first token.</span> <a name="l00142"></a>00142 } <a name="l00143"></a>00143 <a name="l00144"></a>00144 <span class="keyword">public</span>: <a name="l00145"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#e6300cd59e2f0026319f5f8860d086d3">00145</a> iterator() : myTok(0),start(0),tokEnd(0),endp(0),token(0) {} <a name="l00146"></a>00146 <a name="l00147"></a>00147 <span class="comment">// see also: comment in implementation of operator++</span> <a name="l00148"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#365b92953a6e7b19287a12cb9fe61904">00148</a> <span class="keyword">virtual</span> ~iterator() { <span class="keywordflow">if</span> (token) *token=<span class="charliteral">'\0'</span>; <span class="keyword">delete</span> [] token; } <a name="l00149"></a>00149 <a name="l00153"></a>00153 <span class="comment">// everything, but not responsible for the allocated token.</span> <a name="l00154"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#1c99b3999e0c08589666c22830c54b62">00154</a> iterator(<span class="keyword">const</span> iterator& i) : <a name="l00155"></a>00155 myTok(i.myTok),start(i.start),tokEnd(i.tokEnd), <a name="l00156"></a>00156 endp(i.endp),token(0) {} <a name="l00157"></a>00157 <a name="l00161"></a>00161 <span class="comment">// everything, but not responsible for the allocated token.</span> <a name="l00162"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#8cfac0a3036d1a1a41f8bc0e0c837515">00162</a> iterator &operator = (<span class="keyword">const</span> iterator &i) { <a name="l00163"></a>00163 myTok = i.<a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#5b5738b4702d074049c68adc4e748c56">myTok</a>; <a name="l00164"></a>00164 start = i.<a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#58c0f94b3645c85255b9b7fd53593ec2">start</a>; endp = i.<a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#ddf9612fa5fe2fed4c0a46708d8d99f8">endp</a>; tokEnd = i.<a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#ad75244fb1001976c077a97ea3273739">tokEnd</a>; <a name="l00165"></a>00165 <span class="keywordflow">if</span> ( token ) <a name="l00166"></a>00166 <span class="keyword">delete</span> [] token; <a name="l00167"></a>00167 token = 0; <a name="l00168"></a>00168 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00169"></a>00169 } <a name="l00170"></a>00170 <a name="l00174"></a>00174 iterator &operator ++ () <a class="code" href="config_8h.html#9c5a7b689682c471df78bc5892d4ea11">THROWS</a> (<a class="code" href="classost_1_1_string_tokenizer_1_1_no_such_element_exception.html">NoSuchElementException</a>); <a name="l00175"></a>00175 <a name="l00184"></a>00184 const <span class="keywordtype">char</span>* operator * () <a class="code" href="config_8h.html#9c5a7b689682c471df78bc5892d4ea11">THROWS</a> (NoSuchElementException); <a name="l00185"></a>00185 <a name="l00192"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#3aa3b96b05055ef6e58a13c1418b20b7">00192</a> inline <span class="keywordtype">char</span> nextDelimiter()<span class="keyword"> const </span>{ <a name="l00193"></a>00193 <span class="keywordflow">return</span> (tokEnd) ? *tokEnd : <span class="charliteral">'\0'</span>; <a name="l00194"></a>00194 } <a name="l00195"></a>00195 <a name="l00200"></a>00200 <span class="comment">// only compare the end-position. speed.</span> <a name="l00201"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#bc13d5278b0706125d72e28df2e98ba7">00201</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator == (<span class="keyword">const</span> iterator &other)<span class="keyword"> const </span>{ <a name="l00202"></a>00202 <span class="keywordflow">return</span> (endp == other.<a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#ddf9612fa5fe2fed4c0a46708d8d99f8">endp</a>); <a name="l00203"></a>00203 } <a name="l00204"></a>00204 <a name="l00209"></a>00209 <span class="comment">// only compare the end position. speed.</span> <a name="l00210"></a><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#2c844808f928c1f939534c49a12d3a94">00210</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator != (<span class="keyword">const</span> iterator &other)<span class="keyword"> const </span>{ <a name="l00211"></a>00211 <span class="keywordflow">return</span> (endp != other.<a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html#ddf9612fa5fe2fed4c0a46708d8d99f8">endp</a>); <a name="l00212"></a>00212 } <a name="l00213"></a>00213 }; <a name="l00214"></a>00214 <span class="keyword">private</span>: <a name="l00215"></a><a class="code" href="classost_1_1_string_tokenizer.html#46c74d7c3ebac303a827a759155b5879">00215</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classost_1_1_string_tokenizer_1_1iterator.html">StringTokenizer::iterator</a>; <a name="l00216"></a>00216 <span class="keyword">const</span> <span class="keywordtype">char</span> *str; <a name="l00217"></a>00217 <span class="keyword">const</span> <span class="keywordtype">char</span> *delim; <a name="l00218"></a>00218 <span class="keywordtype">bool</span> skipAll, trim; <a name="l00219"></a>00219 iterator itEnd; <a name="l00220"></a>00220 <a name="l00221"></a>00221 <span class="keyword">public</span>: <a name="l00260"></a>00260 StringTokenizer (<span class="keyword">const</span> <span class="keywordtype">char</span> *str, <a name="l00261"></a>00261 <span class="keyword">const</span> <span class="keywordtype">char</span> *delim, <a name="l00262"></a>00262 <span class="keywordtype">bool</span> skipAllDelim = <span class="keyword">false</span>, <a name="l00263"></a>00263 <span class="keywordtype">bool</span> trim = <span class="keyword">false</span>); <a name="l00264"></a>00264 <a name="l00274"></a>00274 StringTokenizer (<span class="keyword">const</span> <span class="keywordtype">char</span> *s); <a name="l00275"></a>00275 <a name="l00279"></a><a class="code" href="classost_1_1_string_tokenizer.html#ec7ea216033f881b2bac13777525e415">00279</a> iterator begin()<span class="keyword"> const </span>{ <a name="l00280"></a>00280 <span class="keywordflow">return</span> iterator(*<span class="keyword">this</span>); <a name="l00281"></a>00281 } <a name="l00282"></a>00282 <a name="l00287"></a><a class="code" href="classost_1_1_string_tokenizer.html#192f7b20b494671b6f69225b4df3e299">00287</a> <span class="keywordtype">void</span> setDelimiters (<span class="keyword">const</span> <span class="keywordtype">char</span> *d) { <a name="l00288"></a>00288 delim = d; <a name="l00289"></a>00289 } <a name="l00290"></a>00290 <a name="l00295"></a><a class="code" href="classost_1_1_string_tokenizer.html#f3dfeb0e48c9d2fc9629076da65acd86">00295</a> iterator begin(<span class="keyword">const</span> <span class="keywordtype">char</span> *d) { <a name="l00296"></a>00296 delim = d; <a name="l00297"></a>00297 <span class="keywordflow">return</span> iterator(*<span class="keyword">this</span>); <a name="l00298"></a>00298 } <a name="l00299"></a>00299 <a name="l00303"></a><a class="code" href="classost_1_1_string_tokenizer.html#74b3471e3e481c0144758385c29cbfbf">00303</a> <span class="keyword">const</span> iterator& end()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> itEnd; } <a name="l00304"></a>00304 }; <a name="l00305"></a>00305 <a name="l00306"></a>00306 <span class="preprocessor">#ifdef CCXX_NAMESPACES</span> <a name="l00307"></a>00307 <span class="preprocessor"></span>} <a name="l00308"></a>00308 <span class="preprocessor">#endif</span> <a name="l00309"></a>00309 <span class="preprocessor"></span> <a name="l00310"></a>00310 <span class="preprocessor">#endif</span> <a name="l00311"></a>00311 <span class="preprocessor"></span> </pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Jun 19 10:50:55 2006 for GNU CommonC++ by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address> </body> </html>