Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
qx-dsvtable.h
1#ifndef QX_DSVTABLE_H
2#define QX_DSVTABLE_H
3
4// Shared Lib Support
5#include "qx/core/qx_core_export.h"
6
7// Qt Includes
8#include <QVariant>
9#include <QSize>
10
11// Intra-component Includes
12#include "qx/core/qx-table.h"
13
14using namespace Qt::Literals::StringLiterals;
15
16namespace Qx
17{
18
19class QX_CORE_EXPORT DsvParseError
20{
21//-Class Enum-----------------------------------------------------------------------------------------------------------
22public:
30
31//-Class Variables------------------------------------------------------------------------------------------------------
32private:
33 static inline const QHash<ParseError, QString> ERROR_STR_MAP{
34 {NoError, u"No error occurred."_s},
35 {IllegalEscape, u"Illegal use of an escape character."_s},
36 {UnterminatedField, u"An escaped field was not properly terminated."_s},
37 {UnevenColumns, u"A row contained a different number of fields than the header row."_s},
38 {InternalError, u"An internal parser error occurred."_s}
39 };
40
41//-Instance Variables------------------------------------------------------------------------------------------------------------
42private:
43 ParseError mError;
44 qsizetype mOffset;
45
46//-Constructor-------------------------------------------------------------------------------------------------
47public:
48 DsvParseError();
49 DsvParseError(ParseError error, qsizetype offset);
50
51//-Instance Functions---------------------------------------------------------------------------------------------------------
52public:
53 ParseError error() const;
54 QString errorString() const;
55 qsizetype offset() const;
56};
57
58class QX_CORE_EXPORT DsvTable : public Table<QVariant>
59{
60//-Constructor----------------------------------------------------------------------------------------------
61public:
62 DsvTable();
63 DsvTable(QSize size);
64 DsvTable(QSize size, const QVariant& value);
65 DsvTable(std::initializer_list<std::initializer_list<QVariant>> table);
66
67//-Class Functions----------------------------------------------------------------------------------------------
68public:
69 static DsvTable fromDsv(const QByteArray& dsv, QChar delim = ',', QChar esc = '"', DsvParseError* error = nullptr);
70
71//-Instance Functions----------------------------------------------------------------------------------------------
72public:
73 QByteArray toDsv(QChar delim = ',', QChar esc = '"');
74};
75
76}
77
78#endif // QX_DSVTABLE_H
The DsvParseError class is used to report errors while parsing an array of delimiter separated values...
Definition qx-dsvtable.h:20
ParseError
Definition qx-dsvtable.h:23
@ UnevenColumns
Definition qx-dsvtable.h:27
@ IllegalEscape
Definition qx-dsvtable.h:25
@ UnterminatedField
Definition qx-dsvtable.h:26
@ NoError
Definition qx-dsvtable.h:24
The DsvTable class provides a mutable representation of delimiter-separated values.
Definition qx-dsvtable.h:59
The Table class is a template class that provides a dynamic two-dimensional array.
Definition qx-table.h:13
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
InternalError