| 1 | <html> |
|---|
| 2 | |
|---|
| 3 | <head> |
|---|
| 4 | <meta http-equiv="Content-Type" |
|---|
| 5 | content="text/html; charset=iso-8859-1"> |
|---|
| 6 | <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> |
|---|
| 7 | <title>Boost Tokenizer Class</title> |
|---|
| 8 | <!-- |
|---|
| 9 | -- Copyright © John Bandela 2001 |
|---|
| 10 | -- |
|---|
| 11 | -- Permission to use, copy, modify, distribute and sell this software |
|---|
| 12 | -- and its documentation for any purpose is hereby granted without fee, |
|---|
| 13 | -- provided that the above copyright notice appears in all copies and |
|---|
| 14 | -- that both that copyright notice and this permission notice appear |
|---|
| 15 | -- in supporting documentation. Jeremy Siek makes no |
|---|
| 16 | -- representations about the suitability of this software for any |
|---|
| 17 | -- purpose. It is provided "as is" without express or implied warranty. |
|---|
| 18 | --> |
|---|
| 19 | </head> |
|---|
| 20 | |
|---|
| 21 | <body bgcolor="#FFFFFF" text="#000000" link="#0000EE" |
|---|
| 22 | vlink="#551A8B" alink="#FF0000"> |
|---|
| 23 | |
|---|
| 24 | <p><img src="../../boost.png" alt="C++ Boost" width="277" |
|---|
| 25 | height="86"> <br> |
|---|
| 26 | </p> |
|---|
| 27 | |
|---|
| 28 | <h1 align="center">Tokenizer Class</h1> |
|---|
| 29 | |
|---|
| 30 | <pre> template < |
|---|
| 31 | class TokenizerFunc = char_delimiters_separator<char>, |
|---|
| 32 | class Iterator = std::string::const_iterator, |
|---|
| 33 | class Type = std::string |
|---|
| 34 | > |
|---|
| 35 | class tokenizer |
|---|
| 36 | </pre> |
|---|
| 37 | |
|---|
| 38 | <p>The tokenizer class provides a container view of a series of |
|---|
| 39 | tokens contained in a sequence. You set the sequence to parse and |
|---|
| 40 | the TokenizerFunction to use to parse the sequence either upon |
|---|
| 41 | construction or using the assign member function. Note: No |
|---|
| 42 | parsing is actually done upon construction. Parsing is done on |
|---|
| 43 | demand as the tokens are accessed via the iterator provided by |
|---|
| 44 | begin.</p> |
|---|
| 45 | |
|---|
| 46 | <h2>Example</h2> |
|---|
| 47 | |
|---|
| 48 | <pre>// simple_example_1.cpp |
|---|
| 49 | #include<iostream> |
|---|
| 50 | #include<boost/tokenizer.hpp> |
|---|
| 51 | #include<string> |
|---|
| 52 | |
|---|
| 53 | int main(){ |
|---|
| 54 | using namespace std; |
|---|
| 55 | using namespace boost; |
|---|
| 56 | string s = "This is, a test"; |
|---|
| 57 | tokenizer<> tok(s); |
|---|
| 58 | for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){ |
|---|
| 59 | cout << *beg << "\n"; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | </pre> |
|---|
| 63 | |
|---|
| 64 | <p> </p> |
|---|
| 65 | |
|---|
| 66 | <h3>Template Parameters</h3> |
|---|
| 67 | |
|---|
| 68 | <table border="1"> |
|---|
| 69 | <tr> |
|---|
| 70 | <th>Parameter</th> |
|---|
| 71 | <th>Description</th> |
|---|
| 72 | </tr> |
|---|
| 73 | <tr> |
|---|
| 74 | <td><tt>TokenizerFunc</tt></td> |
|---|
| 75 | <td>The TokenizerFunction used to parse the sequence.</td> |
|---|
| 76 | </tr> |
|---|
| 77 | <tr> |
|---|
| 78 | <td><tt>Iterator</tt></td> |
|---|
| 79 | <td>The type of the iterator the specifies the sequence.</td> |
|---|
| 80 | </tr> |
|---|
| 81 | <tr> |
|---|
| 82 | <td><tt>Type</tt></td> |
|---|
| 83 | <td>The type of the token, typically string.</td> |
|---|
| 84 | </tr> |
|---|
| 85 | </table> |
|---|
| 86 | |
|---|
| 87 | <p> </p> |
|---|
| 88 | |
|---|
| 89 | <h2>Related Types</h2> |
|---|
| 90 | |
|---|
| 91 | <table border="1"> |
|---|
| 92 | <tr> |
|---|
| 93 | <td><p align="center"><strong>Type</strong></p> |
|---|
| 94 | </td> |
|---|
| 95 | <td><p align="center"><strong>Remarks</strong></p> |
|---|
| 96 | </td> |
|---|
| 97 | </tr> |
|---|
| 98 | <tr> |
|---|
| 99 | <td>iterator</td> |
|---|
| 100 | <td>The type returned by begin and end. Note: the |
|---|
| 101 | category of iterator will be at most ForwardIterator. It |
|---|
| 102 | will be InputIterator if the Iterator template parameter |
|---|
| 103 | is an InputIterator. For any other category, it will be |
|---|
| 104 | ForwardIterator.</td> |
|---|
| 105 | </tr> |
|---|
| 106 | <tr> |
|---|
| 107 | <td>const_iterator</td> |
|---|
| 108 | <td>Same type as iterator.</td> |
|---|
| 109 | </tr> |
|---|
| 110 | <tr> |
|---|
| 111 | <td>value_type</td> |
|---|
| 112 | <td>Same type as the template parameter Type</td> |
|---|
| 113 | </tr> |
|---|
| 114 | <tr> |
|---|
| 115 | <td>reference</td> |
|---|
| 116 | <td>Same type as value_type&</td> |
|---|
| 117 | </tr> |
|---|
| 118 | <tr> |
|---|
| 119 | <td>const_reference</td> |
|---|
| 120 | <td>Same type as const reference</td> |
|---|
| 121 | </tr> |
|---|
| 122 | <tr> |
|---|
| 123 | <td>pointer</td> |
|---|
| 124 | <td>Same type as value_type*</td> |
|---|
| 125 | </tr> |
|---|
| 126 | <tr> |
|---|
| 127 | <td>const_pointer</td> |
|---|
| 128 | <td>Same type as const pointer</td> |
|---|
| 129 | </tr> |
|---|
| 130 | <tr> |
|---|
| 131 | <td>size_type</td> |
|---|
| 132 | <td>void</td> |
|---|
| 133 | </tr> |
|---|
| 134 | <tr> |
|---|
| 135 | <td>difference_type</td> |
|---|
| 136 | <td>void</td> |
|---|
| 137 | </tr> |
|---|
| 138 | </table> |
|---|
| 139 | |
|---|
| 140 | <p> </p> |
|---|
| 141 | |
|---|
| 142 | <h2>Construction and Member Functions</h2> |
|---|
| 143 | |
|---|
| 144 | <pre>tokenizer(Iterator first, Iterator last,const TokenizerFunc& f = TokenizerFunc()) |
|---|
| 145 | |
|---|
| 146 | template<class Container> |
|---|
| 147 | tokenizer(const Container& c,const TokenizerFunc& f = TokenizerFunc()) |
|---|
| 148 | |
|---|
| 149 | void assign(Iterator first, Iterator last) |
|---|
| 150 | |
|---|
| 151 | void assign(Iterator first, Iterator last, const TokenizerFunc& f) |
|---|
| 152 | |
|---|
| 153 | template<class Container> |
|---|
| 154 | void assign(const Container& c) |
|---|
| 155 | |
|---|
| 156 | template<class Container> |
|---|
| 157 | void assign(const Container& c, const TokenizerFunc& f) |
|---|
| 158 | |
|---|
| 159 | iterator begin() const |
|---|
| 160 | |
|---|
| 161 | iterator end() const |
|---|
| 162 | </pre> |
|---|
| 163 | |
|---|
| 164 | <table border="1"> |
|---|
| 165 | <tr> |
|---|
| 166 | <td><p align="center"><strong>Parameter</strong></p> |
|---|
| 167 | </td> |
|---|
| 168 | <td><p align="center"><strong>Description</strong></p> |
|---|
| 169 | </td> |
|---|
| 170 | </tr> |
|---|
| 171 | <tr> |
|---|
| 172 | <td>c</td> |
|---|
| 173 | <td>A container that contains the sequence to parse. Note: |
|---|
| 174 | c.begin() and c.end() must be convertible to the template |
|---|
| 175 | parameter Iterator.</td> |
|---|
| 176 | </tr> |
|---|
| 177 | <tr> |
|---|
| 178 | <td>f</td> |
|---|
| 179 | <td>A functor that is a model of TokenizerFunction that |
|---|
| 180 | will be used to parse the sequence.</td> |
|---|
| 181 | </tr> |
|---|
| 182 | <tr> |
|---|
| 183 | <td>first</td> |
|---|
| 184 | <td>The iterator that represents the beginning position |
|---|
| 185 | in the sequence to be parsed.</td> |
|---|
| 186 | </tr> |
|---|
| 187 | <tr> |
|---|
| 188 | <td>last</td> |
|---|
| 189 | <td>The iterator that represents the past the end |
|---|
| 190 | position in the sequence to be parsed.</td> |
|---|
| 191 | </tr> |
|---|
| 192 | </table> |
|---|
| 193 | |
|---|
| 194 | <p> </p> |
|---|
| 195 | |
|---|
| 196 | <hr> |
|---|
| 197 | |
|---|
| 198 | <p>© Copyright John R. Bandela 2001. Permission to copy, use, |
|---|
| 199 | modify, sell and distribute this document is granted provided |
|---|
| 200 | this copyright notice appears in all copies. This document is |
|---|
| 201 | provided "as is" without express or implied warranty, |
|---|
| 202 | and with no claim as to its suitability for any purpose.</p> |
|---|
| 203 | </body> |
|---|
| 204 | </html> |
|---|