offset_separator.htm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 Offset 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>
  14. <h1 align="center">Offset Separator</h1>
  15. <pre>
  16. class offset_separator
  17. </pre>
  18. <p>The <tt>offset_separator</tt> class is an implementation of the <a href=
  19. "tokenizerfunction.htm">TokenizerFunction</a> concept that can be used with
  20. the <a href="tokenizer.htm">tokenizer</a> class to break text up into
  21. tokens. The <tt>offset_separator</tt> breaks a sequence of <tt>Char</tt>'s
  22. into strings based on a sequence of offsets. For example, if you had the
  23. string "12252001" and offsets (2,2,4) it would break the string into 12 25
  24. 2001. Here is an example.</p>
  25. <h2>Example</h2>
  26. <pre>
  27. // simple_example_3.cpp
  28. #include&lt;iostream&gt;
  29. #include&lt;boost/tokenizer.hpp&gt;
  30. #include&lt;string&gt;
  31. int main(){
  32. using namespace std;
  33. using namespace boost;
  34. string s = "12252001";
  35. int offsets[] = {2,2,4};
  36. offset_separator f(offsets, offsets+3);
  37. tokenizer&lt;offset_separator&gt; tok(s,f);
  38. for(tokenizer&lt;offset_separator&gt;::iterator beg=tok.begin(); beg!=tok.end();++beg){
  39. cout &lt;&lt; *beg &lt;&lt; "\n";
  40. }
  41. }
  42. </pre>
  43. <p>&nbsp;</p>
  44. <h2>Construction and Usage</h2>
  45. <p>The offset_separator has 1 constructor of interest. (The default
  46. constructor is just there to make some compilers happy). The declaration is
  47. below</p>
  48. <pre>
  49. template&lt;typename Iter&gt;
  50. offset_separator(Iter begin,Iter end,bool bwrapoffsets = true, bool breturnpartiallast = true)
  51. </pre>
  52. <table border="1" summary="">
  53. <tr>
  54. <td>
  55. <p align="center"><strong>Parameter</strong></p>
  56. </td>
  57. <td>
  58. <p align="center"><strong>Description</strong></p>
  59. </td>
  60. </tr>
  61. <tr>
  62. <td>begin, end</td>
  63. <td>Specify the sequence of integer offsets.</td>
  64. </tr>
  65. <tr>
  66. <td>bwrapoffsets</td>
  67. <td>Tells whether to wrap around to the beginning of the offsets when
  68. the all the offsets have been used. For example the string
  69. "1225200101012002" with offsets (2,2,4) with bwrapoffsets to true,
  70. would parse to 12 25 2001 01 01 2002. With bwrapoffsets to false, it
  71. would parse to 12 25 2001 and then stop because all the offsets have
  72. been used.</td>
  73. </tr>
  74. <tr>
  75. <td>breturnpartiallast</td>
  76. <td>Tells whether, when the parsed sequence terminates before yielding
  77. the number of characters in the current offset, to create a token with
  78. what was parsed, or to ignore it. For example the string "122501" with
  79. offsets (2,2,4) with breturnpartiallast set to true will parse to 12 25
  80. 01. With it set to false, it will parse to 12 25 and then will stop
  81. because there are only 2 characters left in the sequence instead of the
  82. 4 that should have been there.</td>
  83. </tr>
  84. </table>
  85. <p>To use this class, pass an object of it anywhere a TokenizerFunction is
  86. required. If you default constructruct the object, it will just return
  87. every character in the parsed sequence as a token. (ie it defaults to an
  88. offset of 1, and bwrapoffsets is true).</p>
  89. <p>&nbsp;</p>
  90. <h2>Model of</h2>
  91. <p><a href="tokenizerfunction.htm">TokenizerFunction</a></p>
  92. <hr>
  93. <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
  94. "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
  95. height="31" width="88"></a></p>
  96. <p>Revised
  97. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->25
  98. December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38518" --></p>
  99. <p><i>Copyright &copy; 2001 John R. Bandela</i></p>
  100. <p><i>Distributed under the Boost Software License, Version 1.0. (See
  101. accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  102. copy at <a href=
  103. "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
  104. </body>
  105. </html>