本页内容

Utils::TextFileFormat Class

class Utils::TextFileFormat

TextFileFormat 类描述了文本文件的格式,并提供自动检测功能。更多内容...

Header: #include <TextFileFormat>

公共函数

bool decode(const QByteArray &data, QString *target) const
void detectFromData(const QByteArray &data)
Utils::TextFileFormat::ReadResult readFile(const Utils::FilePath &filePath, const Utils::TextEncoding &fallbackEncoding)
Utils::Result<> writeFile(const Utils::FilePath &filePath, QString plainText) const

静态公共成员

QByteArray decodingErrorSample(const QByteArray &data)

详细说明

该格式包括

  • 由编解码器名称表示的编码
  • 是否存在 UTF-8 字节顺序标记 (BOM)
  • 换行符的存储约定

该类还提供了便利函数,用于读取文本文件并将其作为字符串或字符串列表返回,以及写入文件。

成员函数文档

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

返回将data 解码为字符串的结果:target 。

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

返回由data 指定的文本片段,该文本适用于显示编码错误。

void TextFileFormat::detectFromData(const QByteArray &data)

检测文本data 的格式。

Utils::TextFileFormat::ReadResult TextFileFormat::readFile(const Utils::FilePath &filePath, const Utils::TextEncoding &fallbackEncoding)

从filePath 读取文本文件并将其转换为字符串。它会根据读取的文件内容中的BOM来检测应使用的编解码器。如果未设置编解码器,则使用fallbackEncoding 。如果未设置备用编码,则使用该语言环境设定的文本编码。

返回解码是否成功且未发生错误。如果发生错误,则会返回错误信息以及一个解码错误示例。

Utils::Result<> TextFileFormat::writeFile(const Utils::FilePath &filePath, QString plainText) const

将文本文件写入filePath ,并将其转换为字符串,plainText 。

返回解码是否成功且无错误。

Copyright © The Qt Company Ltd. and other contributors. 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.