forked from qt-creator/qt-creator
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:
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user