TextFileFormat Class

class Utils::TextFileFormat

The TextFileFormat class describes the format of a text file and provides autodetection. More...

Header: #include <TextFileFormat>

Public Functions

bool decode(const class QByteArray &data, class QString *target) const
bool decode(const class QByteArray &data, class QStringList *target) const
bool writeFile(const Utils::FilePath &filePath, class QString plainText, class QString *errorString) const

Static Public Members

class QByteArray decodingErrorSample(const class QByteArray &data)
Utils::TextFileFormat detect(const class QByteArray &data)
Utils::TextFileFormat::ReadResult readFile(const Utils::FilePath &filePath, const QTextCodec *defaultCodec, class QStringList *plainTextList, Utils::TextFileFormat *format, class QString *errorString, class QByteArray *decodingErrorSample = nullptr)
Utils::TextFileFormat::ReadResult readFile(const Utils::FilePath &filePath, const QTextCodec *defaultCodec, class QString *plainText, Utils::TextFileFormat *format, class QString *errorString, class QByteArray *decodingErrorSample = nullptr)

Detailed Description

The format comprises

  • Encoding represented by a pointer to a QTextCodec
  • Presence of an UTF8 Byte Order Marker (BOM)
  • Line feed storage convention

The class also provides convenience functions to read text files and return them as strings or string lists and to write out files.

Member Function Documentation

bool TextFileFormat::decode(const class QByteArray &data, class QString *target) const

Returns data decoded to a plain string, target.

bool TextFileFormat::decode(const class QByteArray &data, class QStringList *target) const

Returns data decoded to a list of strings, target.

Intended for use with progress bars loading large files.

[static] class QByteArray TextFileFormat::decodingErrorSample(const class QByteArray &data)

Returns a piece of text specified by data suitable as display for an encoding error.

[static] Utils::TextFileFormat TextFileFormat::detect(const class QByteArray &data)

Detects the format of text data.

[static] Utils::TextFileFormat::ReadResult TextFileFormat::readFile(const Utils::FilePath &filePath, const QTextCodec *defaultCodec, class QStringList *plainTextList, Utils::TextFileFormat *format, class QString *errorString, class QByteArray *decodingErrorSample = nullptr)

Reads a text file from filePath into a list of strings, plainTextList using defaultCodec and text file format format.

Returns whether decoding was possible without errors. If errors occur, returns an error message, errorString and a sample error, decodingErrorSample.

[static] Utils::TextFileFormat::ReadResult TextFileFormat::readFile(const Utils::FilePath &filePath, const QTextCodec *defaultCodec, class QString *plainText, Utils::TextFileFormat *format, class QString *errorString, class QByteArray *decodingErrorSample = nullptr)

Reads a text file from filePath into a string, plainText using defaultCodec and text file format format.

Returns whether decoding was possible without errors.

bool TextFileFormat::writeFile(const Utils::FilePath &filePath, class QString plainText, class QString *errorString) const

Writes out a text file to filePath into a string, plainText.

Returns whether decoding was possible without errors. If errors occur, returns an error message, errorString.