2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
namespace Lang {
|
|
|
|
|
|
|
|
class FileParser {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2019-06-19 15:42:16 +00:00
|
|
|
using Result = QMap<ushort, QString>;
|
2017-04-13 08:45:58 +00:00
|
|
|
|
2019-06-19 15:42:16 +00:00
|
|
|
FileParser(const QString &file, const std::set<ushort> &request);
|
2018-06-04 15:35:11 +00:00
|
|
|
FileParser(const QByteArray &content, Fn<void(QLatin1String key, const QByteArray &value)> callback);
|
2017-04-13 17:59:05 +00:00
|
|
|
|
|
|
|
static QByteArray ReadFile(const QString &absolutePath, const QString &relativePath);
|
2014-12-19 21:20:30 +00:00
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
const QString &errors() const;
|
|
|
|
const QString &warnings() const;
|
|
|
|
|
|
|
|
Result found() const {
|
|
|
|
return _result;
|
2014-12-19 21:20:30 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
private:
|
2017-04-13 17:59:05 +00:00
|
|
|
void parse();
|
2014-12-19 21:20:30 +00:00
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
bool error(const QString &text) {
|
2017-04-13 08:45:58 +00:00
|
|
|
_errorsList.push_back(text);
|
2017-04-13 17:59:05 +00:00
|
|
|
return false;
|
2017-04-13 08:45:58 +00:00
|
|
|
}
|
|
|
|
void warning(const QString &text) {
|
|
|
|
_warningsList.push_back(text);
|
|
|
|
}
|
2014-12-18 18:40:49 +00:00
|
|
|
bool readKeyValue(const char *&from, const char *end);
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
mutable QStringList _errorsList, _warningsList;
|
|
|
|
mutable QString _errors, _warnings;
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
const QByteArray _content;
|
2019-06-19 15:42:16 +00:00
|
|
|
const std::set<ushort> _request;
|
2018-06-04 15:35:11 +00:00
|
|
|
const Fn<void(QLatin1String key, const QByteArray &value)> _callback;
|
2017-04-13 08:45:58 +00:00
|
|
|
|
|
|
|
Result _result;
|
2014-12-19 21:20:30 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2017-04-13 08:45:58 +00:00
|
|
|
|
|
|
|
} // namespace Lang
|