-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathescaped_list_separator.htm
231 lines (174 loc) · 5.95 KB
/
escaped_list_separator.htm
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Boost Escaped List Separator</title>
</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<Char, Traits = std::char_traits<Char> >
</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,"Field 2, with comma",Field 3<br>
Field 1,Field 2 with \"embedded quote\",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" summary="">
<tr>
<td>
<p align="center"><strong>Escape Sequence</strong></p>
</td>
<td>
<p align="center"><strong>Result</strong></p>
</td>
</tr>
<tr>
<td><escape><quote></td>
<td><quote></td>
</tr>
<tr>
<td><escape>n</td>
<td>newline</td>
</tr>
<tr>
<td><escape><escape></td>
<td><escape></td>
</tr>
</table>
<p>Where <quote> is any character specified to be a quote
and<escape> is any character specified to be an escape character.</p>
<h2>Example</h2>
<pre>
// simple_example_2.cpp
#include<iostream>
#include<boost/tokenizer.hpp>
#include<string>
int main(){
using namespace std;
using namespace boost;
string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
tokenizer<escaped_list_separator<char> > tok(s);
for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg){
cout << *beg << "\n";
}
}
</pre>
<p> </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 = '\"')
</pre>
<table border="1" summary="">
<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> </p>
<pre>
escaped_list_separator(string_type e, string_type c, string_type q):
</pre>
<table border="1" summary="">
<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> </p>
<p>To use this class, pass an object of it anywhere in the Tokenizer
package where a TokenizerFunction is required.</p>
<p> </p>
<h2>Template Parameters</h2>
<table border="1" summary="">
<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<Char></td>
</tr>
</table>
<p> </p>
<h2>Model of</h2>
<p><a href="tokenizerfunction.htm">TokenizerFunction</a></p>
<p> </p>
<hr>
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->25
December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38518" --></p>
<p><i>Copyright © 2001 John R. Bandela</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body>
</html>