Utils: Add a convenience function to TextFileFormat

All these output parameters make for awful code on the calling site.

Change-Id: Ie13294959cc011bc8220bab084e1685f85d8e06b
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2023-08-30 11:33:47 +02:00
parent 495c826c55
commit 164cb389dc
2 changed files with 17 additions and 0 deletions

View File

@@ -288,6 +288,19 @@ TextFileFormat::ReadResult TextFileFormat::readFileUTF8(const FilePath &filePath
return TextFileFormat::ReadSuccess;
}
tl::expected<QString, std::pair<TextFileFormat::ReadResult, QString>>
TextFileFormat::readFile(const FilePath &filePath, const QTextCodec *defaultCodec)
{
QString plainText;
TextFileFormat format;
QString errorString;
const TextFileFormat::ReadResult result =
readTextFile(filePath, defaultCodec, &plainText, &format, &errorString, nullptr);
if (result != TextFileFormat::ReadSuccess)
return tl::unexpected(std::make_pair(result, errorString));
return plainText;
}
/*!
Writes out a text file to \a filePath into a string, \a plainText.