TextFileFormat Class | Extending Qt Creator Manual

Extending Qt Creator Manual | TextFileFormat

Extending Qt Creator Manual 4.6.0

# TextFileFormat Class

(Utils::TextFileFormat)

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

Header: | #include <TextFileFormat>

- List of all members, including inherited members

## Public Types

enum | LineTerminationMode { LFLineTerminator, CRLFLineTerminator, NativeLineTerminator }
enum | ReadResult { ReadSuccess, ReadEncodingError, ReadMemoryAllocationError, ReadIOError }

## Public Functions

| TextFileFormat()
bool | decode(const QByteArray &data, QString *target) const
bool | decode(const QByteArray &data, QStringList *target) const
bool | writeFile(const QString &fileName, QString plainText, QString *errorString) const

## Static Public Members

QByteArray | decodingErrorSample(const QByteArray &data)
TextFileFormat | detect(const QByteArray &data)
ReadResult | readFile(const QString &fileName, const QTextCodec *defaultCodec, QStringList *plainTextList, TextFileFormat *format, QString *errorString, QByteArray *decodingErrorSample = 0)
ReadResult | readFile(const QString &fileName, const QTextCodec *defaultCodec, QString *plainText, TextFileFormat *format, QString *errorString, QByteArray *decodingErrorSample = 0)
ReadResult | readFileUTF8(const QString &fileName, const QTextCodec *defaultCodec, QByteArray *plainText, QString *errorString)

## Detailed Description

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

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 Type Documentation

### enum TextFileFormat::LineTerminationMode

### enum TextFileFormat::ReadResult

## Member Function Documentation

### TextFileFormat::TextFileFormat()

Default constructs an instance of TextFileFormat.

### 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]` TextFileFormat TextFileFormat::detect(const QByteArray &data)

Detects the format of text data.

### `[static]` ReadResult TextFileFormat::readFile(const QString &fileName, const QTextCodec *defaultCodec, QStringList *plainTextList, TextFileFormat *format, QString *errorString, QByteArray *decodingErrorSample = 0)

Reads a text file into a list of strings.

### `[static]` ReadResult TextFileFormat::readFile(const QString &fileName, const QTextCodec *defaultCodec, QString *plainText, TextFileFormat *format, QString *errorString, QByteArray *decodingErrorSample = 0)

Reads a text file into a string.

### `[static]` ReadResult TextFileFormat::readFileUTF8(const QString &fileName, const QTextCodec *defaultCodec, QByteArray *plainText, QString *errorString)

### bool TextFileFormat::writeFile(const QString &fileName, QString plainText, QString *errorString) const

Writes out a text file.