File: escaped_list_separator.htm

package info (click to toggle)
boost 1.32.0-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 93,952 kB
  • ctags: 128,458
  • sloc: cpp: 492,477; xml: 52,125; python: 13,519; ansic: 13,013; sh: 1,773; yacc: 853; makefile: 526; perl: 418; lex: 110; csh: 6
file content (201 lines) | stat: -rw-r--r-- 6,043 bytes parent folder | download | duplicates (2)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<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 Escaped List 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">

<h1 align="left"><img src="../../boost.png" alt="C++ Boost"
width="277" height="86"> </h1>

<h1 align="center">Escaped List Separator</h1>
<div align="left">

<pre>
escaped_list_separator&lt;Char, Traits = std::char_traits&lt;Char&gt; &gt;
</pre>
</div>

<p>The <tt>escaped_list_separator</tt> class is an implementation
of the <a href="tokenizerfunction.htm">TokenizerFunction</a>. The
escaped_list_separator parses a superset of the csv (comma
separated value) format. The examples of this formate are below.
It is assumed that the default characters for separator, quote,
and escape are used.</p>

<p>Field 1,Field 2,Field 3<br>
Field 1,&quot;Field 2, with comma&quot;,Field 3<br>
Field 1,Field 2 with \&quot;embedded quote\&quot;,Field 3<br>
Field 1, Field 2 with \n new line,Field 3<br>
Field 1, Field 2 with embedded \\ ,Field 3</p>

<p>Fields are normally separated by commas. If you want to put a
comma in a field, you need to put quotes around it. Also 3 escape
sequences are supported</p>

<table border="1">
    <tr>
        <td><p align="center"><strong>Escape Sequence</strong></p>
        </td>
        <td><p align="center"><strong>Result</strong></p>
        </td>
    </tr>
    <tr>
        <td>&lt;escape&gt;&lt;quote&gt;</td>
        <td>&lt;quote&gt;</td>
    </tr>
    <tr>
        <td>&lt;escape&gt;n</td>
        <td>newline</td>
    </tr>
    <tr>
        <td>&lt;escape&gt;&lt;escape&gt;</td>
        <td>&lt;escape&gt;</td>
    </tr>
</table>

<p>Where &lt;quote&gt; is any character specified to be a quote
and&lt;escape&gt; is any character specified to be an escape
character.</p>

<h2>Example</h2>

<pre>// simple_example_2.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;Field 1,\&quot;putting quotes around fields, allows commas\&quot;,Field 3&quot;;
   tokenizer&lt;escaped_list_separator&lt;char&gt; &gt; tok(s);
   for(tokenizer&lt;escaped_list_separator&lt;char&gt; &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>escaped_list_separator has 2 constructors. They are as follows</p>

<pre>explicit escaped_list_separator(Char e = '\\', Char c = ',',Char q = '\&quot;')</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>e</td>
        <td>Specifies the character to use for escape sequences.
        It defaults to the C style \ (backslash). However you can
        override by passing in a different character. An example
        of when you might want to do this is when you have many
        fields which are Windows style filenames. Instead of
        escaping out each \ in the path, you can change the
        escape to something else.</td>
    </tr>
    <tr>
        <td>c</td>
        <td>Specifies the character to use to separate the fields</td>
    </tr>
    <tr>
        <td>q</td>
        <td>Specifies the character to use for the quote.</td>
    </tr>
</table>

<p>&nbsp;</p>

<pre>escaped_list_separator(string_type e, string_type c, string_type q):</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>e</td>
        <td>Any character in the string e, is considered to be an
        escape character. If an empty string is given, then there
        are no escape characters.</td>
    </tr>
    <tr>
        <td>c</td>
        <td>Any character in the string c, is considered to be a
        separator. If an empty string is given, then there are no
        separator characters.</td>
    </tr>
    <tr>
        <td>q</td>
        <td>Any character in the string q, is considered to be a
        quote. If an empty string is given, then there are no
        quote characters.</td>
    </tr>
</table>

<p>&nbsp;</p>

<p>To use this class, pass an object of it anywhere in the
Tokenizer package where a TokenizerFunction is required.</p>

<p>&nbsp;</p>

<h2>Template Parameters</h2>

<table border="1">
    <tr>
        <th><strong>Parameter</strong></th>
        <th><strong>Description</strong></th>
    </tr>
    <tr>
        <td><tt>Char</tt></td>
        <td>The type of the elements within a token, typically <tt>char</tt>.</td>
    </tr>
    <tr>
        <td>Traits</td>
        <td>The traits class for the Char type. This is used for
        comparing Char's. It defaults to std::char_traits&lt;Char&gt;</td>
    </tr>
</table>

<p>&nbsp;</p>

<h2>Model of</h2>

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

<p>&nbsp;</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>