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 QByteArray &data, QString *target) const
bool decode(const QByteArray &data, QStringList *target) const
bool writeFile(const Utils::FilePath &filePath, QString plainText, QString *errorString) const

Static Public Members

QByteArray decodingErrorSample(const QByteArray &data)
Utils::TextFileFormat detect(const QByteArray &data)
Utils::TextFileFormat::ReadResult readFile(const Utils::FilePath &filePath, const QTextCodec *defaultCodec, QStringList *plainTextList, Utils::TextFileFormat *format, QString *errorString, QByteArray *decodingErrorSample = nullptr)
Utils::TextFileFormat::ReadResult readFile(const Utils::FilePath &filePath, const QTextCodec *defaultCodec, QString *plainText, Utils::TextFileFormat *format, QString *errorString, 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 QByteArray &data, QString *target) const

Decodes data to a plain string.

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

Decodes data to a list of strings.

Intended for use with progress bars loading large files.

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

Returns a piece of text suitable as display for a encoding error.

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

Detects the format of text data.

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

Reads a text file into a list of strings.

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

Reads a text file into a string.

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

Writes out a text file.

© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.