2016-04-16 17:51:25 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-16 17:51:25 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-16 17:51:25 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtCore/QByteArray>
|
|
|
|
#include <QtCore/QVector>
|
|
|
|
|
|
|
|
#include "codegen/common/logging.h"
|
|
|
|
|
|
|
|
namespace codegen {
|
|
|
|
namespace common {
|
|
|
|
|
|
|
|
// Reads a file removing all C-style comments.
|
|
|
|
class CleanFile {
|
|
|
|
public:
|
2016-04-18 20:33:43 +00:00
|
|
|
explicit CleanFile(const QString &filepath);
|
2016-04-18 22:00:54 +00:00
|
|
|
explicit CleanFile(const QByteArray &content, const QString &filepath = QString());
|
2016-04-16 17:51:25 +00:00
|
|
|
CleanFile(const CleanFile &other) = delete;
|
|
|
|
CleanFile &operator=(const CleanFile &other) = delete;
|
|
|
|
|
|
|
|
bool read();
|
2017-02-03 20:07:26 +00:00
|
|
|
QVector<QByteArray> singleLineComments() const;
|
2016-04-16 17:51:25 +00:00
|
|
|
|
|
|
|
const char *data() const {
|
2016-04-18 22:00:54 +00:00
|
|
|
return result_.constData();
|
2016-04-16 17:51:25 +00:00
|
|
|
}
|
|
|
|
const char *end() const {
|
2016-04-18 22:00:54 +00:00
|
|
|
return result_.constEnd();
|
2016-04-16 17:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr int MaxSize = 10 * 1024 * 1024;
|
|
|
|
|
|
|
|
// Log error to std::cerr with 'code' at line number 'line' in data().
|
|
|
|
LogStream logError(int code, int line) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString filepath_;
|
2016-04-18 22:00:54 +00:00
|
|
|
QByteArray content_, result_;
|
|
|
|
bool read_;
|
2017-02-03 20:07:26 +00:00
|
|
|
|
|
|
|
QVector<QByteArray> singleLineComments_;
|
2016-04-16 17:51:25 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace common
|
|
|
|
} // namespace codegen
|