$darkmode
Qore CsvUtil Module Reference
1.10
CsvHelper.qc.dox.h
1
// -*- mode: c++; indent-tabs-mode: nil -*-
2
// Qore CsvHelper class definition
3
4
/* CsvHelper.qm Copyright 2012 - 2023 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
"bool"
:
True
,
36
"*bool"
:
True
,
37
"int"
:
True
,
38
"*int"
:
True
,
39
"float"
:
True
,
40
"*float"
:
True
,
41
"number"
:
True
,
42
"*number"
:
True
,
43
"string"
:
True
,
44
"*string"
:
True
,
45
"date"
:
True
,
46
"*date"
:
True
,
47
};
48
50
const
FieldAttrs = (
"type"
,
"format"
,
"timezone"
,
"code"
,
"header"
);
51
53
bool
tolwr =
False
;
54
56
string
date_format;
57
59
string
number_format;
60
62
hash
m_specs;
63
65
string
errname;
66
67
// reorder data according headers set by options.headers or read from CsvHeader
68
bool
headerReorder =
True
;
69
70
public
:
71
73
constructor (
string
n_errname);
74
75
77
*hash<string, AbstractDataField> getRecordType();
78
79
81
protected
:
82
bool
isMultiType();
83
public
:
84
85
87
protected
:
88
checkType(
string
fld_errs,
string
key,
string
value);
89
public
:
90
91
92
// get spec from options.fields for old Csv. Check spec param for new Csv
93
protected
:
94
hash
getSpec(*
hash
fields,
string
fld_errs,
int
C_OPTx);
95
public
:
96
97
98
protected
:
99
hash
getSpec1(*
hash
fields);
100
public
:
101
102
103
protected
:
104
hash
getSpec2(
hash
spec);
105
public
:
106
107
112
protected
:
113
list<string> adjustFieldsFromHeaders(
string
type
, *list<auto> headers,
bool
check =
False
);
114
public
:
115
116
};
// class CsvHelper
True
const True
False
const False
type
string type(auto arg)
hash
hash< auto > hash(object obj)