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 "codegen/common/clean_file.h"
|
|
|
|
|
|
|
|
namespace codegen {
|
|
|
|
namespace common {
|
|
|
|
|
|
|
|
// Wrapper allows you to read forward the CleanFile without overflow checks.
|
|
|
|
class CleanFileReader {
|
|
|
|
public:
|
2016-04-18 22:00:54 +00:00
|
|
|
explicit CleanFileReader(const QString &filepath) : file_(filepath) {
|
|
|
|
}
|
|
|
|
explicit CleanFileReader(const QByteArray &content, const QString &filepath = QString()) : file_(content, filepath) {
|
2016-04-16 17:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool read() {
|
|
|
|
if (!file_.read()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pos_ = file_.data();
|
|
|
|
end_ = file_.end();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool atEnd() const {
|
|
|
|
return (pos_ == end_);
|
|
|
|
}
|
|
|
|
char currentChar() const {
|
|
|
|
return atEnd() ? 0 : *pos_;
|
|
|
|
}
|
|
|
|
bool skipChar() {
|
|
|
|
if (atEnd()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
++pos_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const char *currentPtr() const {
|
|
|
|
return pos_;
|
|
|
|
}
|
2016-04-18 22:00:54 +00:00
|
|
|
int charsLeft() const {
|
|
|
|
return (end_ - pos_);
|
|
|
|
}
|
2016-04-16 17:51:25 +00:00
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
QVector<QByteArray> singleLineComments() const {
|
|
|
|
return file_.singleLineComments();
|
|
|
|
}
|
|
|
|
|
2016-04-16 17:51:25 +00:00
|
|
|
// Log error to std::cerr with 'code' at line number 'line' in data().
|
|
|
|
LogStream logError(int code, int line) const {
|
|
|
|
return std::forward<LogStream>(file_.logError(code, line));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
CleanFile file_;
|
|
|
|
const char *pos_ = nullptr;
|
|
|
|
const char *end_ = nullptr;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace common
|
|
|
|
} // namespace codegen
|