LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
CsvControl.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
29 #ifndef LSST_AP_UTILS_CSVCONTROL_H
30 #define LSST_AP_UTILS_CSVCONTROL_H
31 
32 #include <string>
33 
34 #include "lsst/pex/config.h"
35 
36 
37 namespace lsst { namespace ap { namespace utils {
38 
48 struct CsvControl {
49  enum Quoting {
50  QUOTE_NONE = 0,
53  };
54 
55  CsvControl();
56  ~CsvControl();
57 
58  LSST_CONTROL_FIELD(null, std::string,
59  "String representation of NULL field values. Never quoted on output.\n"
60  "If specified, the representation may not contain any delimiter,\n"
61  "quote, escape or line terminator characters ('\\n'/'\\r').\n");
62 
64  "Indicates whether the null string is valid. If set to false, the only\n"
65  "way NULLs can be recognized/written is if standardEscapes is set to\n"
66  "true (in which case '\\N' is mapped to NULL, assuming that '\\' is\n"
67  "the escape character).\n");
68 
69  LSST_CONTROL_FIELD(quoting, std::string,
70  "Field quoting style for CSV input/output. Legal values are:\n"
71  "\n"
72  "'QUOTE_MINIMAL': Only quote fields when necessary - for instance,\n"
73  " when a field value contains a delimiter character.\n"
74  "\n"
75  "'QUOTE_NONE': Never quote fields.\n"
76  "\n"
77  "'QUOTE_ALL': Always quote fields.\n");
78 
79  LSST_CONTROL_FIELD(delimiter, std::string,
80  "A one character string containing the field delimiter character.\n"
81  "Values of '\\0', '\\n', or '\\r' are illegal.\n");
82 
83  LSST_CONTROL_FIELD(escapeChar, std::string,
84  "A one character string containing the escape character. An empty\n"
85  "string is mapped to an escape character of '\\0', which disables\n"
86  "escaping. A value equal to the delimiter or quote character is\n"
87  "illegal, with one exception: both the escape and quote characters\n"
88  "can be '\\0'. The '\\n' and '\\r' characters are also illegal.\n");
89 
90  LSST_CONTROL_FIELD(quoteChar, std::string,
91  "A one character string containing the character used to quote fields\n"
92  "when quoting is set to either 'QUOTE_ALL' or 'QUOTE_MINIMAL'. An\n"
93  "empty string is mapped to a quote character of '\\0', which disables\n"
94  "quoting (and is only legal when quoting is set to 'QUOTE_NONE'). A\n"
95  "value equal to the delimiter or quote character is illegal, with one\n"
96  "exception: both the escape and quote characters can be '\\0'. The\n"
97  "'\\n' and '\\r' characters are also illegal.\n");
98 
100  "If true, whitespace immediately following the delimiter is ignored.");
101 
103  "If true, embedded quote characters are escaped with a leading quote\n"
104  "character. Otherwise the escape character is used. If escaping and\n"
105  "double-quoting are disabled, writing a field with embedded quote\n"
106  "character will raise an exception.\n");
107 
109  "Flag indicating whether standard escape sequences should be handled.\n"
110  "If false, then the character sequence '\\C', where C is any character,\n"
111  "is mapped to C (assuming '\\' is the escape character). If true,\n"
112  "the following special cases are handled differently:\n"
113  "\n"
114  "- '\\b' is mapped to BS - backspace (ASCII 8)\n"
115  "- '\\f' is mapped to FF - form feed (ASCII 12)\n"
116  "- '\\n' is mapped to NL - newline (ASCII 10)\n"
117  "- '\\r' is mapped to CR - carriage return (ASCII 13)\n"
118  "- '\\t' is mapped to TAB - horizontal tab (ASCII 9)\n"
119  "- '\\v' is mapped to VT - vertical tab (ASCII 11)\n"
120  "- '\\xD' and '\\xDD', where D is a hexadecimal digit, is mapped to\n"
121  " the character with that numeric code.\n"
122  "- A field value of exactly '\\N' (no quotes, whitespace, or other\n"
123  " content) is treated as a NULL.\n");
124 
126  "If true, then a trailing delimiter character is expected and written\n"
127  "at end of every record, immediately preceding the line terminator.\n");
128 
130  "If true, then non-finite (NaN, Inf, -Inf) floating point values are\n"
131  "written out as NULL field values.\n");
132 
138  inline bool isNullRecognizable() const {
139  return hasNull || standardEscapes;
140  }
141 
146  inline Quoting getQuoting() const {
147  if (quoting == "QUOTE_MINIMAL") {
148  return QUOTE_MINIMAL;
149  } else if (quoting == "QUOTE_ALL") {
150  return QUOTE_ALL;
151  }
152  return QUOTE_NONE;
153  }
154 
155  inline char getDelimiter() const {
156  return delimiter.c_str()[0];
157  }
158  inline char getEscapeChar() const {
159  return escapeChar.c_str()[0];
160  }
161  inline char getQuoteChar() const {
162  return quoteChar.c_str()[0];
163  }
164 
165  void validate() const;
166 };
167 
168 }}} // namespace lsst::ap::utils
169 
170 #endif // LSST_AP_UTILS_CSVCONTROL_H
171 
char getDelimiter() const
Definition: CsvControl.h:155
char getEscapeChar() const
Definition: CsvControl.h:158
char getQuoteChar() const
Definition: CsvControl.h:161
Parameters that define a Character-Separated-Value dialect.
Definition: CsvControl.h:48
Quoting getQuoting() const
Definition: CsvControl.h:146
Only quote fields when necessary.
Definition: CsvControl.h:52
bool nonfiniteAsNull
&quot;If true, then non-finite (NaN, Inf, -Inf) floating point values are\n&quot; &quot;written out as NULL field va...
Definition: CsvControl.h:131
std::string delimiter
&quot;A one character string containing the field delimiter character.\n&quot; &quot;Values of &#39;\\0&#39;...
Definition: CsvControl.h:81
std::string null
&quot;String representation of NULL field values. Never quoted on output.\n&quot; &quot;If specified, the representation may not contain any delimiter,\n&quot; &quot;quote, escape or line terminator characters (&#39;\\n&#39;/&#39;\\r&#39;).\n&quot; ;
Definition: CsvControl.h:61
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
Definition: config.h:36
bool isNullRecognizable() const
Definition: CsvControl.h:138
std::string escapeChar
&quot;A one character string containing the escape character. An empty\n&quot; &quot;string is mapped to an escap...
Definition: CsvControl.h:88
bool skipInitialSpace
&quot;If true, whitespace immediately following the delimiter is ignored.&quot; ;
Definition: CsvControl.h:100
std::string quoting
&quot;Field quoting style for CSV input/output. Legal values are:\n&quot; &quot;\n&quot; &quot;&#39;QUOTE_MINIMAL&#39;: Only quot...
Definition: CsvControl.h:77
bool hasNull
&quot;Indicates whether the null string is valid. If set to false, the only\n&quot; &quot;way NULLs can be recogn...
Definition: CsvControl.h:67
bool standardEscapes
&quot;Flag indicating whether standard escape sequences should be handled.\n&quot; &quot;If false, then the character sequence &#39;\\C&#39;, where C is any character,\n&quot; &quot;is mapped to C (assuming &#39;\\&#39; is the escape character). If true,\n&quot; &quot;the following special cases are handled differently:\n&quot; &quot;\n&quot; &quot;- &#39;\\b&#39; is mapped to BS - backspace (ASCII 8)\n&quot; &quot;- &#39;\\f&#39; is mapped to FF - form feed (ASCII 12)\n&quot; &quot;- &#39;\\n&#39; is mapped to NL - newline (ASCII 10)\n&quot; &quot;- &#39;\\r&#39; is mapped to CR - carriage return (ASCII 13)\n&quot; &quot;- &#39;\\t&#39; is mapped to TAB - horizontal tab (ASCII 9)\n&quot; &quot;- &#39;\\v&#39; is mapped to VT - vertical tab (ASCII 11)\n&quot; &quot;- &#39;\\xD&#39; and &#39;\\xDD&#39;, where D is a hexadecimal digit, is mapped to\n&quot; &quot; the character with that numeric code.\n&quot; &quot;- A field value of exactly &#39;\\N&#39; (no quotes, whitespace, or other\n&quot; &quot; content) is treated as a NULL.\n&quot; ;
Definition: CsvControl.h:123
bool trailingDelimiter
&quot;If true, then a trailing delimiter character is expected and written\n&quot; &quot;at end of every record...
Definition: CsvControl.h:127
bool doubleQuote
&quot;If true, embedded quote characters are escaped with a leading quote\n&quot; &quot;character. Otherwise the escape character is used. If escaping and\n&quot; &quot;double-quoting are disabled, writing a field with embedded quote\n&quot; &quot;character will raise an exception.\n&quot; ;
Definition: CsvControl.h:106
std::string quoteChar
&quot;A one character string containing the character used to quote fields\n&quot; &quot;when quoting is set to e...
Definition: CsvControl.h:97