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();
|
return file.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileReader::fetch(const FilePath &filePath)
|
Result<> FileReader::fetch(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
const Result<QByteArray> contents = filePath.fileContents();
|
const Result<QByteArray> contents = filePath.fileContents();
|
||||||
if (!contents) {
|
if (!contents)
|
||||||
m_errorString = contents.error();
|
return ResultError(contents.error());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_data = *contents;
|
m_data = *contents;
|
||||||
return true;
|
return ResultOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray FileReader::text() const
|
QByteArray FileReader::text() const
|
||||||
@@ -76,10 +75,11 @@ QByteArray FileReader::text() const
|
|||||||
|
|
||||||
bool FileReader::fetch(const FilePath &filePath, QString *errorString)
|
bool FileReader::fetch(const FilePath &filePath, QString *errorString)
|
||||||
{
|
{
|
||||||
if (fetch(filePath))
|
const Result<> res = fetch(filePath);
|
||||||
|
if (res)
|
||||||
return true;
|
return true;
|
||||||
if (errorString)
|
if (errorString)
|
||||||
*errorString = m_errorString;
|
*errorString = res.error();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -143,14 +143,13 @@ class QTCREATOR_UTILS_EXPORT FileReader
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static QByteArray fetchQrc(const QString &fileName); // Only for internal resources
|
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);
|
bool fetch(const FilePath &filePath, QString *errorString);
|
||||||
const QByteArray &data() const { return m_data; }
|
const QByteArray &data() const { return m_data; }
|
||||||
QByteArray text() const; // data with replaced \r\n -> \n
|
QByteArray text() const; // data with replaced \r\n -> \n
|
||||||
const QString &errorString() const { return m_errorString; }
|
|
||||||
private:
|
private:
|
||||||
QByteArray m_data;
|
QByteArray m_data;
|
||||||
QString m_errorString;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT FileSaverBase
|
class QTCREATOR_UTILS_EXPORT FileSaverBase
|
||||||
|
Reference in New Issue
Block a user