Qore CsvUtil Module Reference  1.7.2
CsvHelper.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // Qore CsvHelper class definition
3 
4 /* CsvHelper.qm Copyright 2012 - 2020 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // assume local var scope, do not use "$" for vars, members, and method calls
26 
27 class CsvHelper {
28 
29 public:
30 protected:
31  const C_OPT1 = 0x1;
32  const C_OPT2 = 0x2;
34  const Types = ...;
35 
36 
38  const FieldAttrs = ("type", "format", "timezone", "code", "header");
39 
41  bool tolwr = False;
42 
44  string date_format;
45 
47  string number_format;
48 
50  hash m_specs;
51 
53  string errname;
54 
55  // reorder data according headers set by options.headers or read from CsvHeader
56  bool headerReorder = True;
57 
58 public:
59 
61  constructor (string n_errname);
62 
63 
65  *hash<string, AbstractDataField> getRecordType();
66 
67 
69 protected:
70  bool isMultiType();
71 public:
72 
73 
75 protected:
76  checkType(string fld_errs, string key, string value);
77 public:
78 
79 
80  // get spec from options.fields for old Csv. Check spec param for new Csv
81 protected:
82  hash getSpec(*hash fields, string fld_errs, int C_OPTx);
83 public:
84 
85 
86 protected:
87  hash getSpec1(*hash fields);
88 public:
89 
90 
91 protected:
92  hash getSpec2(hash spec);
93 public:
94 
95 
100 protected:
101  list<string> adjustFieldsFromHeaders(string type, *list<auto> headers, bool check = False);
102 public:
103 
104 }; // class CsvHelper
const True
const False
string type(auto arg)
hash< auto > hash(object obj)