tokenizer.htm 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Language" content="en-us">
  5. <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
  6. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  7. <meta name="ProgId" content="FrontPage.Editor.Document">
  8. <title>Boost Tokenizer Class</title>
  9. </head>
  10. <body bgcolor="#FFFFFF" text="#000000" link="#0000EE" vlink="#551A8B" alink=
  11. "#FF0000">
  12. <p><img src="../../../boost.png" alt="C++ Boost" width="277" height=
  13. "86"><br></p>
  14. <h1 align="center">Tokenizer Class</h1>
  15. <pre> template &lt;
  16. class TokenizerFunc = char_delimiters_separator&lt;char&gt;,
  17. class Iterator = std::string::const_iterator,
  18. class Type = std::string
  19. &gt;
  20. class tokenizer
  21. </pre>
  22. <p>The tokenizer class provides a container view of a series of tokens
  23. contained in a sequence. You set the sequence to parse and the
  24. TokenizerFunction to use to parse the sequence either upon construction or
  25. using the assign member function. Note: No parsing is actually done upon
  26. construction. Parsing is done on demand as the tokens are accessed via the
  27. iterator provided by begin.</p>
  28. <h2>Example</h2>
  29. <pre>// simple_example_1.cpp
  30. #include&lt;iostream&gt;
  31. #include&lt;boost/tokenizer.hpp&gt;
  32. #include&lt;string&gt;
  33. int main(){
  34. using namespace std;
  35. using namespace boost;
  36. string s = "This is, a test";
  37. tokenizer&lt;&gt; tok(s);
  38. for(tokenizer&lt;&gt;::iterator beg=tok.begin(); beg!=tok.end();++beg){
  39. cout &lt;&lt; *beg &lt;&lt; "\n";
  40. }
  41. }
  42. </pre>
  43. <p>The output from simple_example_1 is:</p>
  44. <blockquote>
  45. <p><code>This<br>
  46. is<br>
  47. a<br>
  48. test</code></p>
  49. </blockquote>
  50. <h3>Template Parameters</h3>
  51. <table border="1" summary="">
  52. <tr>
  53. <th>Parameter</th>
  54. <th>Description</th>
  55. </tr>
  56. <tr>
  57. <td><tt>TokenizerFunc</tt></td>
  58. <td>The TokenizerFunction used to parse the sequence.</td>
  59. </tr>
  60. <tr>
  61. <td><tt>Iterator</tt></td>
  62. <td>The type of the iterator the specifies the sequence.</td>
  63. </tr>
  64. <tr>
  65. <td><tt>Type</tt></td>
  66. <td>The type of the token, typically string.</td>
  67. </tr>
  68. </table>
  69. <p>&nbsp;</p>
  70. <h2>Related Types</h2>
  71. <table border="1" summary="">
  72. <tr>
  73. <td>
  74. <p align="center"><strong>Type</strong></p>
  75. </td>
  76. <td>
  77. <p align="center"><strong>Remarks</strong></p>
  78. </td>
  79. </tr>
  80. <tr>
  81. <td>iterator</td>
  82. <td>The type returned by begin and end. Note: the category of iterator
  83. will be at most ForwardIterator. It will be InputIterator if the
  84. Iterator template parameter is an InputIterator. For any other
  85. category, it will be ForwardIterator.</td>
  86. </tr>
  87. <tr>
  88. <td>const_iterator</td>
  89. <td>Same type as iterator.</td>
  90. </tr>
  91. <tr>
  92. <td>value_type</td>
  93. <td>Same type as the template parameter Type</td>
  94. </tr>
  95. <tr>
  96. <td>reference</td>
  97. <td>Same type as value_type&amp;</td>
  98. </tr>
  99. <tr>
  100. <td>const_reference</td>
  101. <td>Same type as const reference</td>
  102. </tr>
  103. <tr>
  104. <td>pointer</td>
  105. <td>Same type as value_type*</td>
  106. </tr>
  107. <tr>
  108. <td>const_pointer</td>
  109. <td>Same type as const pointer</td>
  110. </tr>
  111. <tr>
  112. <td>size_type</td>
  113. <td>void</td>
  114. </tr>
  115. <tr>
  116. <td>difference_type</td>
  117. <td>void</td>
  118. </tr>
  119. </table>
  120. <p>&nbsp;</p>
  121. <h2>Construction and Member Functions</h2>
  122. <pre>tokenizer(Iterator first, Iterator last,const TokenizerFunc&amp; f = TokenizerFunc())
  123. template&lt;class Container&gt;
  124. tokenizer(const Container&amp; c,const TokenizerFunc&amp; f = TokenizerFunc())
  125. void assign(Iterator first, Iterator last)
  126. void assign(Iterator first, Iterator last, const TokenizerFunc&amp; f)
  127. template&lt;class Container&gt;
  128. void assign(const Container&amp; c)
  129. template&lt;class Container&gt;
  130. void assign(const Container&amp; c, const TokenizerFunc&amp; f)
  131. iterator begin() const
  132. iterator end() const
  133. </pre>
  134. <table border="1" summary="">
  135. <tr>
  136. <td>
  137. <p align="center"><strong>Parameter</strong></p>
  138. </td>
  139. <td>
  140. <p align="center"><strong>Description</strong></p>
  141. </td>
  142. </tr>
  143. <tr>
  144. <td>c</td>
  145. <td>A container that contains the sequence to parse. Note: c.begin()
  146. and c.end() must be convertible to the template parameter
  147. Iterator.</td>
  148. </tr>
  149. <tr>
  150. <td>f</td>
  151. <td>A functor that is a model of TokenizerFunction that will be used to
  152. parse the sequence.</td>
  153. </tr>
  154. <tr>
  155. <td>first</td>
  156. <td>The iterator that represents the beginning position in the sequence
  157. to be parsed.</td>
  158. </tr>
  159. <tr>
  160. <td>last</td>
  161. <td>The iterator that represents the past the end position in the
  162. sequence to be parsed.</td>
  163. </tr>
  164. </table>
  165. <p>&nbsp;</p>
  166. <hr>
  167. <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
  168. "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
  169. height="31" width="88"></a></p>
  170. <p>Revised
  171. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->16 February, 2008<!--webbot bot="Timestamp" endspan i-checksum="40414" --></p>
  172. <p><i>Copyright &copy; 2001 John R. Bandela</i></p>
  173. <p><i>Distributed under the Boost Software License, Version 1.0. (See
  174. accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  175. copy at <a href=
  176. "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
  177. </body>
  178. </html>