forked from qt-creator/qt-creator
Utils: Return Result<> from FileReader::fetch()
... instead of keeping an internal error string. Change-Id: Ic529a8bd1ba2a89b3ca3d039e0f98632738960cd Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -56,15 +56,14 @@ QByteArray FileReader::fetchQrc(const QString &fileName)
|
||||
return file.readAll();
|
||||
}
|
||||
|
||||
bool FileReader::fetch(const FilePath &filePath)
|
||||
Result<> FileReader::fetch(const FilePath &filePath)
|
||||
{
|
||||
const Result<QByteArray> contents = filePath.fileContents();
|
||||
if (!contents) {
|
||||
m_errorString = contents.error();
|
||||
return false;
|
||||
}
|
||||
if (!contents)
|
||||
return ResultError(contents.error());
|
||||
|
||||
m_data = *contents;
|
||||
return true;
|
||||
return ResultOk;
|
||||
}
|
||||
|
||||
QByteArray FileReader::text() const
|
||||
@@ -76,10 +75,11 @@ QByteArray FileReader::text() const
|
||||
|
||||
bool FileReader::fetch(const FilePath &filePath, QString *errorString)
|
||||
{
|
||||
if (fetch(filePath))
|
||||
const Result<> res = fetch(filePath);
|
||||
if (res)
|
||||
return true;
|
||||
if (errorString)
|
||||
*errorString = m_errorString;
|
||||
*errorString = res.error();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -143,14 +143,13 @@ class QTCREATOR_UTILS_EXPORT FileReader
|
||||
{
|
||||
public:
|
||||
static QByteArray fetchQrc(const QString &fileName); // Only for internal resources
|
||||
bool fetch(const FilePath &filePath);
|
||||
Result<> fetch(const FilePath &filePath);
|
||||
bool fetch(const FilePath &filePath, QString *errorString);
|
||||
const QByteArray &data() const { return m_data; }
|
||||
QByteArray text() const; // data with replaced \r\n -> \n
|
||||
const QString &errorString() const { return m_errorString; }
|
||||
|
||||
private:
|
||||
QByteArray m_data;
|
||||
QString m_errorString;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT FileSaverBase
|
||||
|
Reference in New Issue
Block a user