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.cc
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 
30 
31 #include "lsst/pex/exceptions.h"
32 
33 
34 using std::string;
35 using lsst::pex::exceptions::InvalidParameterError;
36 
37 namespace lsst { namespace ap { namespace utils {
38 
40  null(),
41  hasNull(false),
42  quoting("QUOTE_MINIMAL"),
43  delimiter(","),
44  escapeChar("\\"),
45  quoteChar("\""),
46  skipInitialSpace(false),
47  doubleQuote(false),
48  standardEscapes(true),
49  trailingDelimiter(false),
50  nonfiniteAsNull(false)
51 {
52  validate();
53 }
54 
56 
57 void CsvControl::validate() const {
58  if (delimiter.size() != 1) {
59  throw LSST_EXCEPT(InvalidParameterError,
60  "delimiter must consist of a single character");
61  }
62  if (delimiter[0] == '\0' || delimiter[0] == '\n' || delimiter[0] == '\r') {
63  throw LSST_EXCEPT(InvalidParameterError,
64  "delimiter equal to '\\[0nr]'");
65 
66  }
67  if (escapeChar.size() > 1) {
68  throw LSST_EXCEPT(InvalidParameterError,
69  "escapeChar string contains more than one character");
70 
71  }
72  if (escapeChar == delimiter ||
73  getEscapeChar() == '\n' || getEscapeChar() == '\r') {
74  throw LSST_EXCEPT(InvalidParameterError,
75  "escapeChar equal to delimiter or '\\[nr]'.");
76  }
77  if (quoteChar.size() > 1) {
78  throw LSST_EXCEPT(InvalidParameterError,
79  "quoteChar string contains more than one character");
80  }
81  if (quoteChar == delimiter ||
82  getQuoteChar() == '\n' || getQuoteChar() == '\r') {
83  throw LSST_EXCEPT(InvalidParameterError,
84  "quoteChar equal to delimiter or '\\[nr]'.");
85  }
86  if (escapeChar == quoteChar && getEscapeChar() != '\0') {
87  throw LSST_EXCEPT(InvalidParameterError,
88  "escapeChar equal to quoteChar. Did you mean to use "
89  "the doubleQuote option instead?");
90  }
91  if (getEscapeChar() == '\0' && standardEscapes) {
92  throw LSST_EXCEPT(InvalidParameterError,
93  "escapeChar set to '\\0', but standardEscapes = true");
94  }
95  if (quoting != "QUOTE_MINIMAL" && quoting != "QUOTE_ALL" &&
96  quoting != "QUOTE_NONE") {
97  throw LSST_EXCEPT(InvalidParameterError,
98  "quoting must be one of 'QUOTE_MINIMAL', 'QUOTE_ALL' "
99  "or 'QUOTE_NONE'");
100  }
101  if (getQuoteChar() == '\0' && quoting != "QUOTE_NONE") {
102  throw LSST_EXCEPT(InvalidParameterError,
103  "quoteChar set to '\\0', but quoting is not "
104  "'QUOTE_NONE'");
105  }
106  if (null.find('\n') != string::npos ||
107  null.find('\r') != string::npos ||
108  null.find(getDelimiter()) != string::npos ||
109  null.find(getEscapeChar()) != string::npos ||
110  null.find(getQuoteChar()) != string::npos) {
111  throw LSST_EXCEPT(InvalidParameterError,
112  "null string contains '\\n', '\\r', delimiter, "
113  "escapeChar, or quoteChar.");
114  }
115 }
116 
117 }}} // namespace lsst::ap::utils
char getDelimiter() const
Definition: CsvControl.h:155
char getEscapeChar() const
Definition: CsvControl.h:158
char getQuoteChar() const
Definition: CsvControl.h:161
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
CSV format control.
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
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
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 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
Include files required for standard LSST Exception handling.
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