Krita Source Code Documentation
Loading...
Searching...
No Matches
csv_read_line.cpp
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2016 Laszlo Fazekas <mneko@freemail.hu>
3
*
4
* SPDX-License-Identifier: GPL-2.0-or-later
5
*/
6
7
#include "
csv_read_line.h
"
8
9
#include <
kis_debug.h
>
10
11
#include <QDebug>
12
#include <QIODevice>
13
14
#include <
asl/kis_offset_keeper.h
>
15
#include <
asl/kis_asl_writer_utils.h
>
16
#include <
asl/kis_asl_reader_utils.h
>
17
18
CSVReadLine::CSVReadLine
()
19
: m_separator(0)
20
, m_row(0)
21
, m_linebuf(0)
22
, m_pos(-1)
23
{
24
}
25
26
CSVReadLine::~CSVReadLine
()
27
{
28
}
29
30
// returns: 0 finished, + continue, - error
31
int
CSVReadLine::nextLine
(QIODevice *io)
32
{
33
int
retval= 0;
34
m_pos
= -1;
35
36
try
{
37
m_linebuf
= io->readLine();
38
39
if
(!
m_linebuf
.size())
40
retval= 0;
//finished
41
else
{
42
if
(!
m_separator
)
43
m_separator
= ((
m_linebuf
.size() > 5) && (
m_linebuf
[5] ==
';'
)) ?
44
';'
:
','
;
45
m_pos
= 0;
46
retval= 1;
47
}
48
}
catch
(
KisAslReaderUtils::ASLParseException
&e) {
49
warnKrita
<<
"WARNING: CSV:"
<< e.what();
50
retval= -1;
//error
51
}
52
return
retval;
53
}
54
55
QString
CSVReadLine::nextField
()
56
{
57
char
strBuf[
CSV_FIELD_MAX
];
58
char
*ptr;
59
char
c;
60
int
i,
p
,max;
61
62
p
=
m_pos
;
63
64
if
(
p
< 0)
return
QString();
65
66
ptr= strBuf;
67
max=
m_linebuf
.size();
68
69
do
{
if
(
p
>= max) {
70
ptr[0]= 0;
71
m_pos
= -1;
72
return
QString(strBuf);
73
}
74
c=
m_linebuf
[
p
++];
75
}
while
((c ==
' '
) || (c ==
'\t'
));
76
77
i= 0;
78
79
if
(c ==
'\"'
) {
80
//quoted
81
while
(
p
< max) {
82
c=
m_linebuf
[
p
++];
83
84
if
(c ==
'\"'
) {
85
86
if
(
p
>= max)
break
;
87
88
if
(
m_linebuf
[
p
] != c)
break
;
89
90
//double quote escape sequence
91
++
p
;
92
}
93
if
(i < (
CSV_FIELD_MAX
- 1))
94
ptr[i++]= c;
95
}
96
97
while
(
p
< max) {
98
c=
m_linebuf
[
p
++];
99
if
(c ==
m_separator
)
break
;
100
}
101
}
else
{
102
//without quotes
103
while
(c !=
m_separator
) {
104
if
(i < (
CSV_FIELD_MAX
- 1))
105
ptr[i++]= c;
106
107
if
(
p
>= max)
break
;
108
109
c=
m_linebuf
[
p
++];
110
}
111
112
while
(i > 0) {
113
c= ptr[--i];
114
if
((c !=
' '
) && (c !=
'\t'
) &&
115
(c !=
'\r'
) && (c !=
'\n'
)) {
116
++i;
117
break
;
118
}
119
}
120
}
121
ptr[i]= 0;
122
m_pos
= (
p
< max) ?
p
: -1;
123
return
QString(strBuf);
124
}
125
126
void
CSVReadLine::rewind
()
127
{
128
m_pos
= 0;
129
}
p
const Params2D p
Definition
KisBezierUtils.cpp:703
CSVReadLine::nextField
QString nextField()
Definition
csv_read_line.cpp:55
CSVReadLine::nextLine
int nextLine(QIODevice *io)
Definition
csv_read_line.cpp:31
CSVReadLine::CSVReadLine
CSVReadLine()
Definition
csv_read_line.cpp:18
CSVReadLine::m_pos
int m_pos
Definition
csv_read_line.h:44
CSVReadLine::rewind
void rewind()
Definition
csv_read_line.cpp:126
CSVReadLine::~CSVReadLine
~CSVReadLine()
Definition
csv_read_line.cpp:26
CSVReadLine::m_linebuf
QByteArray m_linebuf
Definition
csv_read_line.h:43
CSVReadLine::m_separator
char m_separator
Definition
csv_read_line.h:41
csv_read_line.h
CSV_FIELD_MAX
#define CSV_FIELD_MAX
Definition
csv_read_line.h:20
kis_asl_reader_utils.h
kis_asl_writer_utils.h
kis_debug.h
warnKrita
#define warnKrita
Definition
kis_debug.h:87
kis_offset_keeper.h
KisAslReaderUtils::ASLParseException
Definition
kis_asl_reader_utils.h:36
plugins
impex
csv
csv_read_line.cpp
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52