File: offset_separator.htm

package info (click to toggle)
boost 1.27.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,908 kB
  • ctags: 26,546
  • sloc: cpp: 122,225; ansic: 10,956; python: 4,412; sh: 855; yacc: 803; makefile: 257; perl: 165; lex: 90; csh: 6
file content (129 lines) | stat: -rw-r--r-- 4,382 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Boost Offset Separator</title>
<!--
  -- Copyright  John Bandela 2001
  --
  -- Permission to use, copy, modify, distribute and sell this software
  -- and its documentation for any purpose is hereby granted without fee,
  -- provided that the above copyright notice appears in all copies and
  -- that both that copyright notice and this permission notice appear
  -- in supporting documentation.  Jeremy Siek makes no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  -->
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000EE"
vlink="#551A8B" alink="#FF0000">

<p><img src="../../c++boost.gif" alt="C++ Boost" width="277"
height="86"> <br>
</p>

<h1 align="center">Offset Separator</h1>

<pre>
class offset_separator
</pre>

<p>The <tt>offset_separator</tt> class is an implementation of
the <a href="tokenizerfunction.htm">TokenizerFunction</a> concept
that can be used with the <a href="tokenizer.htm">tokenizer</a>
class to break text up into tokens. The <tt>offset_separator</tt>
breaks a sequence of <tt>Char</tt>'s into strings based on a
sequence of offsets. For example, if you had the string &quot;12252001&quot;
and offsets (2,2,4) it would break the string into 12 25 2001.
Here is an example.</p>

<h2>Example</h2>

<pre>// simple_example_3.cpp
#include&lt;iostream&gt;
#include&lt;boost/tokenizer.hpp&gt;
#include&lt;string&gt;

int main(){
   using namespace std;
   using namespace boost;
   string s = &quot;12252001&quot;;
   int offsets[] = {2,2,4};
   offset_separator f(offsets, offsets+3);
   tokenizer&lt;offset_separator&gt; tok(s,f);
   for(tokenizer&lt;offset_separator&gt;::iterator beg=tok.begin(); beg!=tok.end();++beg){
     cout &lt;&lt; *beg &lt;&lt; &quot;\n&quot;;
   }
}</pre>

<p>&nbsp;</p>

<h2>Construction and Usage</h2>

<p>The offset_separator has 1 constructor of interest. (The
default constructor is just there to make some compilers happy).
The declaration is below</p>

<pre>template&lt;typename Iter&gt;
offset_separator(Iter begin,Iter end,bool bwrapoffsets = true, bool breturnpartiallast = true)
</pre>

<table border="1">
    <tr>
        <td><p align="center"><strong>Parameter</strong></p>
        </td>
        <td><p align="center"><strong>Description</strong></p>
        </td>
    </tr>
    <tr>
        <td>begin, end</td>
        <td>Specify the sequence of integer offsets.</td>
    </tr>
    <tr>
        <td>bwrapoffsets</td>
        <td>Tells whether to wrap around to the beginning of the
        offsets when the all the offsets have been used. For
        example the string &quot;1225200101012002&quot; with
        offsets (2,2,4) with bwrapoffsets to true, would parse to
        12 25 2001 01 01 2002. With bwrapoffsets to false, it
        would parse to 12 25 2001 and then stop because all the
        offsets have been used.</td>
    </tr>
    <tr>
        <td>breturnpartiallast</td>
        <td>Tells whether, when the parsed sequence terminates
        before yielding the number of characters in the current
        offset, to create a token with what was parsed, or to
        ignore it. For example the string &quot;122501&quot; with
        offsets (2,2,4) with breturnpartiallast set to true will
        parse to 12 25 01. With it set to false, it will parse to
        12 25 and then will stop because there are only 2
        characters left in the sequence instead of the 4 that
        should have been there.</td>
    </tr>
</table>

<p>To use this class, pass an object of it anywhere a
TokenizerFunction is required. If you default constructruct the
object, it will just return every character in the parsed
sequence as a token. (ie it defaults to an offset of 1, and
bwrapoffsets is true).</p>

<p>&nbsp;</p>

<h2>Model of</h2>

<p><a href="tokenizerfunction.htm">TokenizerFunction</a> </p>

<hr>

<p> Copyright John R. Bandela 2001. Permission to copy, use,
modify, sell and distribute this document is granted provided
this copyright notice appears in all copies. This document is
provided &quot;as is&quot; without express or implied warranty,
and with no claim as to its suitability for any purpose.</p>
</body>
</html>