16 #include <QDataStream>
21 #include <QRegularExpression>
22 #include <QRegularExpressionMatch>
23 #include "../../util/cp1252.h"
24 #include "../../util/directory.h"
25 #include "../keys/cswordldkey.h"
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wextra-semi"
30 #pragma GCC diagnostic ignored "-Wsuggest-override"
31 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
33 #pragma clang diagnostic push
34 #pragma clang diagnostic ignored "-Wsuggest-destructor-override"
39 #pragma clang diagnostic pop
41 #pragma GCC diagnostic pop
45 #define CACHE_FORMAT "3"
56 module.setPosition(sword::TOP);
58 QString key = QString::fromUtf8(module.getKeyText());
59 QRegularExpression rx1(QStringLiteral(
"^[GH][0-9]+$"));
60 if (rx1.match(key).hasMatch()) {
65 QRegularExpression rx2(QStringLiteral(
"^[0-9]+$"));
66 if (rx2.match(key).hasMatch()) {
81 QFile cacheFile(QStringLiteral(
"%1/%2")
87 if (cacheFile.open(QIODevice::ReadOnly)) {
88 QDataStream s(&cacheFile);
92 s >> QDataStreamVersion;
94 qDebug() <<
"Lexicon cache metadata"
97 <<
"CacheVersion" << CacheVersion
98 <<
"QDataStreamVersion" << QDataStreamVersion;
103 && QDataStreamVersion == QString::number(s.version())) {
107 qDebug() <<
"Read" <<
m_entries.count() <<
"entries from lexicon cache for module" <<
name();
117 qDebug() <<
"Read all entries of lexicon" <<
name();
120 m.setSkipConsecutiveLinks(
true);
121 m.setPosition(sword::TOP);
126 m_entries.append(QString::fromUtf8(m.getKeyText()));
128 }
while (!m.popError());
133 }
while (!m.popError());
136 m.setPosition(sword::TOP);
137 m.setSkipConsecutiveLinks(
false);
143 qDebug() <<
"Writing cache file for lexicon module" <<
name();
147 if (cacheFile.open( QIODevice::WriteOnly )) {
148 QDataStream s(&cacheFile);
151 << QString::number(s.version())
168 if (
auto const match =
169 QRegularExpression(QStringLiteral(
"^([GH]?)0*([0-9]+?)$"))
173 auto const lang = match.capturedView(1);
174 auto const digits = match.capturedView(2);
179 auto numPaddingZeroesRequired = size - digits.size();
183 normalized.reserve(size);
185 normalized.append(lang);
186 while (numPaddingZeroesRequired--)
187 normalized.append(
'0');
188 normalized.append(digits);
The backend layer main class, a backend implementation of Sword.
bool hasStrongsKeys() const
int m_strongsDigitsLength
bool m_hasLeadingStrongsLetter
CSwordLexiconModuleInfo(sword::SWModule &module, CSwordBackend &backend)
QString normalizeStrongsKey(const QString &key) const
CSwordKey * createKey() const final override
const QStringList & entries() const
bool snap() const final override
QString config(const CSwordModuleInfo::ConfigEntry entry) const
bool isUnicode() const noexcept
QString const & name() const
sword::SWModule & swordModule() const
std::unique_ptr< CSwordBackend > backend(sword::InstallSource const &is)
QString toUnicode(QByteArray const &data)
const QDir & getUserCacheDir()