char_delimiters_separator.htm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 6.0">
  7. <meta name="ProgId" content="FrontPage.Editor.Document">
  8. <title>Boost Char Delimiters Separator</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><font color="red">Note: This class is deprecated. Please use
  14. <a href="char_separator.htm"><tt>char_separator</tt></a> instead.</font>
  15. <h1 align="center">Char Delimiters Separator</h1>
  16. <pre>
  17. template &lt;class Char, class Traits = std::char_traits&lt;Char&gt; &gt;
  18. class char_delimiters_separator{
  19. </pre>
  20. <p>The char_delimiters_separator class is an implementation of the <a href=
  21. "tokenizerfunction.htm">TokenizerFunction</a> concept that can be used to
  22. break text up into tokens. It is the default TokenizerFunction for
  23. tokenizer and token_iterator_generator. An example is below.</p>
  24. <h2>Example</h2>
  25. <pre>
  26. // simple_example_4.cpp
  27. #include&lt;iostream&gt;
  28. #include&lt;boost/tokenizer.hpp&gt;
  29. #include&lt;string&gt;
  30. int main(){
  31. using namespace std;
  32. using namespace boost;
  33. string s = "This is, a test";
  34. tokenizer&lt;char_delimiters_separator&lt;char&gt; &gt; tok(s);
  35. for(tokenizer&lt;char_delimiters_separator&lt;char&gt; &gt;::iterator beg=tok.begin(); beg!=tok.end();++beg){
  36. cout &lt;&lt; *beg &lt;&lt; "\n";
  37. }
  38. }
  39. </pre>
  40. <h2>Construction and Usage</h2>
  41. <p>There is one constructor of interest. It is as follows</p>
  42. <pre>
  43. explicit char_delimiters_separator(bool return_delims = false,
  44. const Char* returnable = "",const Char* nonreturnable = "" )
  45. </pre>
  46. <table border="1" summary="">
  47. <tr>
  48. <td>
  49. <p align="center"><strong>Parameter</strong></p>
  50. </td>
  51. <td>
  52. <p align="center"><strong>Description</strong></p>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td>return_delims</td>
  57. <td>Whether or not to return the delimiters that have been found. Note
  58. that not all delimiters can be returned. See the other two parameters
  59. for explanation.</td>
  60. </tr>
  61. <tr>
  62. <td>returnable</td>
  63. <td>This specifies the returnable delimiters. These are the delimiters
  64. that can be returned as tokens when return_delims is true. Since these
  65. are typically punctuation, if a 0 is provided as the argument, then the
  66. returnable delmiters will be all characters Cfor which std::ispunct(C)
  67. yields a true value. If an argument of "" is provided, then this is
  68. taken to mean that there are noreturnable delimiters.</td>
  69. </tr>
  70. <tr>
  71. <td>nonreturnable</td>
  72. <td>This specifies the nonreturnable delimiters. These are delimiters
  73. that cannot be returned as tokens. Since these are typically
  74. whitespace, if 0 is specified as an argument, then the nonreturnable
  75. delimiters will be all characters C for which std::isspace(C) yields a
  76. true value. If an argument of "" is provided, then this is taken to
  77. mean that there are no non-returnable delimiters.</td>
  78. </tr>
  79. </table>
  80. <p>The reason there is a distinction between nonreturnable and returnable
  81. delimiters is that some delimiters are just used to split up tokens and are
  82. nothing more. Take for example the following string "b c +". Assume you are
  83. writing a simple calculator to parse expression in post fix notation. While
  84. both the space and the + separate tokens, you only only interested in the +
  85. and not in the space. Indeed having the space returned as a token would
  86. only complicate your code. In this case you would specify + as a
  87. returnable, and space as a nonreturnable delimiter.</p>
  88. <p>To use this class, pass an object of it anywhere a TokenizerFunction
  89. object is required.</p>
  90. <h3>Template Parameters</h3>
  91. <table border="1" summary="">
  92. <tr>
  93. <th>Parameter</th>
  94. <th>Description</th>
  95. </tr>
  96. <tr>
  97. <td><tt>Char</tt></td>
  98. <td>The type of the elements within a token, typically
  99. <tt>char</tt>.</td>
  100. </tr>
  101. <tr>
  102. <td>Traits</td>
  103. <td>The traits class for Char, typically
  104. std::char_traits&lt;Char&gt;</td>
  105. </tr>
  106. </table>
  107. <h2>Model of</h2>
  108. <p><a href="tokenizerfunction.htm">TokenizerFunction</a></p>
  109. <p>&nbsp;</p>
  110. <hr>
  111. <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
  112. "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
  113. height="31" width="88"></a></p>
  114. <p>Revised
  115. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->25
  116. December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38518" --></p>
  117. <p><i>Copyright &copy; 2001 John R. Bandela</i></p>
  118. <p><i>Distributed under the Boost Software License, Version 1.0. (See
  119. accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  120. copy at <a href=
  121. "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
  122. </body>
  123. </html>