The CsvFile class represents a comma-separated values (CSV) file.
More...
#include <csvfile.h>
|
static QString | escapeValue (const QString &value) noexcept |
|
The CsvFile class represents a comma-separated values (CSV) file.
The class allows building CSV and write them to a file. It is guaranteed that the written files are valid:
- Whenn adding a row with a wrong value count, addValue() throws an exception.
- Linebreaks inside values are replaced by spaces.
- If a value contains the separator character (e.g. the comma), the value gets quoted.
- Quotes inside values are escaped.
- Note
- You have to call setHeader() before adding any values with addValue()! This is needed to make sure all value rows have the same value count as the header.
- See also
- https://en.wikipedia.org/wiki/Comma-separated_values
◆ CsvFile() [1/2]
◆ CsvFile() [2/2]
◆ ~CsvFile()
◆ getComment()
const QString & getComment |
( |
| ) |
const |
|
inlinenoexcept |
Get the comment of the file.
- Returns
- File comment (raw comment without '#' at beginning of lines).
◆ getHeader()
const QStringList & getHeader |
( |
| ) |
const |
|
inlinenoexcept |
Get the CSV header items.
- Returns
- CSV header items (raw, i.e. without quotes and escaped characters).
◆ getValues()
const QList< QStringList > & getValues |
( |
| ) |
const |
|
inlinenoexcept |
Get the CSV values.
- Returns
- All value rows (raw, i.e. without quotes and escaped characters).
◆ setComment()
void setComment |
( |
const QString & |
comment | ) |
|
|
noexcept |
Set file comment.
- Parameters
-
comment | The comment to set. May contain linebreaks. |
◆ setHeader()
void setHeader |
( |
const QStringList & |
header | ) |
|
|
noexcept |
Set the header items.
- Parameters
-
header | The new header items. |
- Warning
- This method clears all values!
◆ addValue()
void addValue |
( |
const QStringList & |
value | ) |
|
Add a row of values.
- Parameters
-
value | The value row items. |
- Exceptions
-
◆ toString()
QString toString |
( |
| ) |
const |
|
noexcept |
Build CSV file content and return it as a string.
- Returns
- The string with the whole CSV file content.
◆ saveToFile()
void saveToFile |
( |
const FilePath & |
csvFp | ) |
const |
Write CSV file content to a file.
- Parameters
-
csvFp | The destination file path. |
- Exceptions
-
◆ operator=()
◆ getCommentLines()
QString getCommentLines |
( |
| ) |
const |
|
privatenoexcept |
◆ lineToString()
QString lineToString |
( |
const QStringList & |
line | ) |
const |
|
privatenoexcept |
◆ escapeValue()
QString escapeValue |
( |
const QString & |
value | ) |
|
|
staticprivatenoexcept |
◆ mComment
◆ mHeader
◆ mValues
QList<QStringList> mValues |
|
private |
The documentation for this class was generated from the following files: