Krita Source Code Documentation
Loading...
Searching...
No Matches
CSVReadLine Class Reference

#include <csv_read_line.h>

Public Member Functions

 CSVReadLine ()
 
QString nextField ()
 
int nextLine (QIODevice *io)
 
void rewind ()
 
 ~CSVReadLine ()
 

Private Member Functions

bool finalize ()
 
bool readFrame (int *pos)
 
int readImpl (QIODevice *io)
 
bool setLayer (CSVLayerRecord *)
 
QString splitNext (int *pos)
 

Private Attributes

QByteArray m_linebuf
 
int m_pos
 
int m_row
 
char m_separator
 

Detailed Description

Definition at line 22 of file csv_read_line.h.

Constructor & Destructor Documentation

◆ CSVReadLine()

CSVReadLine::CSVReadLine ( )

Definition at line 18 of file csv_read_line.cpp.

19 : m_separator(0)
20 , m_row(0)
21 , m_linebuf(0)
22 , m_pos(-1)
23{
24}
QByteArray m_linebuf

◆ ~CSVReadLine()

CSVReadLine::~CSVReadLine ( )

Definition at line 26 of file csv_read_line.cpp.

27{
28}

Member Function Documentation

◆ finalize()

bool CSVReadLine::finalize ( )
private

◆ nextField()

QString CSVReadLine::nextField ( )

Definition at line 55 of file csv_read_line.cpp.

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}
const Params2D p
#define CSV_FIELD_MAX
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References CSV_FIELD_MAX, m_linebuf, m_pos, m_separator, and p.

◆ nextLine()

int CSVReadLine::nextLine ( QIODevice * io)

Definition at line 31 of file csv_read_line.cpp.

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 }
49 warnKrita << "WARNING: CSV:" << e.what();
50 retval= -1; //error
51 }
52 return retval;
53}
#define warnKrita
Definition kis_debug.h:87

References m_linebuf, m_pos, m_separator, and warnKrita.

◆ readFrame()

bool CSVReadLine::readFrame ( int * pos)
private

◆ readImpl()

int CSVReadLine::readImpl ( QIODevice * io)
private

◆ rewind()

void CSVReadLine::rewind ( )

Definition at line 126 of file csv_read_line.cpp.

127{
128 m_pos= 0;
129}

References m_pos.

◆ setLayer()

bool CSVReadLine::setLayer ( CSVLayerRecord * )
private

◆ splitNext()

QString CSVReadLine::splitNext ( int * pos)
private

Member Data Documentation

◆ m_linebuf

QByteArray CSVReadLine::m_linebuf
private

Definition at line 43 of file csv_read_line.h.

◆ m_pos

int CSVReadLine::m_pos
private

Definition at line 44 of file csv_read_line.h.

◆ m_row

int CSVReadLine::m_row
private

Definition at line 42 of file csv_read_line.h.

◆ m_separator

char CSVReadLine::m_separator
private

Definition at line 41 of file csv_read_line.h.


The documentation for this class was generated from the following files: