escaped_list_separator.htm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 Escaped List Separator</title>
  9. </head>
  10. <body bgcolor="#FFFFFF" text="#000000" link="#0000EE" vlink="#551A8B" alink=
  11. "#FF0000">
  12. <h1 align="left"><img src="../../../boost.png" alt="C++ Boost" width="277"
  13. height="86"></h1>
  14. <h1 align="center">Escaped List Separator</h1>
  15. <div align="left">
  16. <pre>
  17. escaped_list_separator&lt;Char, Traits = std::char_traits&lt;Char&gt; &gt;
  18. </pre>
  19. </div>
  20. <p>The <tt>escaped_list_separator</tt> class is an implementation of the
  21. <a href="tokenizerfunction.htm">TokenizerFunction</a>. The
  22. escaped_list_separator parses a superset of the csv (comma separated value)
  23. format. The examples of this formate are below. It is assumed that the
  24. default characters for separator, quote, and escape are used.</p>
  25. <p>Field 1,Field 2,Field 3<br>
  26. Field 1,"Field 2, with comma",Field 3<br>
  27. Field 1,Field 2 with \"embedded quote\",Field 3<br>
  28. Field 1, Field 2 with \n new line,Field 3<br>
  29. Field 1, Field 2 with embedded \\ ,Field 3</p>
  30. <p>Fields are normally separated by commas. If you want to put a comma in a
  31. field, you need to put quotes around it. Also 3 escape sequences are
  32. supported</p>
  33. <table border="1" summary="">
  34. <tr>
  35. <td>
  36. <p align="center"><strong>Escape Sequence</strong></p>
  37. </td>
  38. <td>
  39. <p align="center"><strong>Result</strong></p>
  40. </td>
  41. </tr>
  42. <tr>
  43. <td>&lt;escape&gt;&lt;quote&gt;</td>
  44. <td>&lt;quote&gt;</td>
  45. </tr>
  46. <tr>
  47. <td>&lt;escape&gt;n</td>
  48. <td>newline</td>
  49. </tr>
  50. <tr>
  51. <td>&lt;escape&gt;&lt;escape&gt;</td>
  52. <td>&lt;escape&gt;</td>
  53. </tr>
  54. </table>
  55. <p>Where &lt;quote&gt; is any character specified to be a quote
  56. and&lt;escape&gt; is any character specified to be an escape character.</p>
  57. <h2>Example</h2>
  58. <pre>
  59. // simple_example_2.cpp
  60. #include&lt;iostream&gt;
  61. #include&lt;boost/tokenizer.hpp&gt;
  62. #include&lt;string&gt;
  63. int main(){
  64. using namespace std;
  65. using namespace boost;
  66. string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
  67. tokenizer&lt;escaped_list_separator&lt;char&gt; &gt; tok(s);
  68. for(tokenizer&lt;escaped_list_separator&lt;char&gt; &gt;::iterator beg=tok.begin(); beg!=tok.end();++beg){
  69. cout &lt;&lt; *beg &lt;&lt; "\n";
  70. }
  71. }
  72. </pre>
  73. <p>&nbsp;</p>
  74. <h2>Construction and Usage</h2>
  75. <p>escaped_list_separator has 2 constructors. They are as follows</p>
  76. <pre>
  77. explicit escaped_list_separator(Char e = '\\', Char c = ',',Char q = '\"')
  78. </pre>
  79. <table border="1" summary="">
  80. <tr>
  81. <td>
  82. <p align="center"><strong>Parameter</strong></p>
  83. </td>
  84. <td>
  85. <p align="center"><strong>Description</strong></p>
  86. </td>
  87. </tr>
  88. <tr>
  89. <td>e</td>
  90. <td>Specifies the character to use for escape sequences. It defaults to
  91. the C style \ (backslash). However you can override by passing in a
  92. different character. An example of when you might want to do this is
  93. when you have many fields which are Windows style filenames. Instead of
  94. escaping out each \ in the path, you can change the escape to something
  95. else.</td>
  96. </tr>
  97. <tr>
  98. <td>c</td>
  99. <td>Specifies the character to use to separate the fields</td>
  100. </tr>
  101. <tr>
  102. <td>q</td>
  103. <td>Specifies the character to use for the quote.</td>
  104. </tr>
  105. </table>
  106. <p>&nbsp;</p>
  107. <pre>
  108. escaped_list_separator(string_type e, string_type c, string_type q):
  109. </pre>
  110. <table border="1" summary="">
  111. <tr>
  112. <td>
  113. <p align="center"><strong>Parameter</strong></p>
  114. </td>
  115. <td>
  116. <p align="center"><strong>Description</strong></p>
  117. </td>
  118. </tr>
  119. <tr>
  120. <td>e</td>
  121. <td>Any character in the string e, is considered to be an escape
  122. character. If an empty string is given, then there are no escape
  123. characters.</td>
  124. </tr>
  125. <tr>
  126. <td>c</td>
  127. <td>Any character in the string c, is considered to be a separator. If
  128. an empty string is given, then there are no separator characters.</td>
  129. </tr>
  130. <tr>
  131. <td>q</td>
  132. <td>Any character in the string q, is considered to be a quote. If an
  133. empty string is given, then there are no quote characters.</td>
  134. </tr>
  135. </table>
  136. <p>&nbsp;</p>
  137. <p>To use this class, pass an object of it anywhere in the Tokenizer
  138. package where a TokenizerFunction is required.</p>
  139. <p>&nbsp;</p>
  140. <h2>Template Parameters</h2>
  141. <table border="1" summary="">
  142. <tr>
  143. <th><strong>Parameter</strong></th>
  144. <th><strong>Description</strong></th>
  145. </tr>
  146. <tr>
  147. <td><tt>Char</tt></td>
  148. <td>The type of the elements within a token, typically
  149. <tt>char</tt>.</td>
  150. </tr>
  151. <tr>
  152. <td>Traits</td>
  153. <td>The traits class for the Char type. This is used for comparing
  154. Char's. It defaults to std::char_traits&lt;Char&gt;</td>
  155. </tr>
  156. </table>
  157. <p>&nbsp;</p>
  158. <h2>Model of</h2>
  159. <p><a href="tokenizerfunction.htm">TokenizerFunction</a></p>
  160. <p>&nbsp;</p>
  161. <hr>
  162. <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
  163. "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
  164. height="31" width="88"></a></p>
  165. <p>Revised
  166. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->25
  167. December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38518" --></p>
  168. <p><i>Copyright &copy; 2001 John R. Bandela</i></p>
  169. <p><i>Distributed under the Boost Software License, Version 1.0. (See
  170. accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  171. copy at <a href=
  172. "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
  173. </body>
  174. </html>