60 module.setPosition(sword::TOP);
62 QString key = QString::fromUtf8(module.getKeyText());
63 QRegularExpression rx1(QStringLiteral(
"^[GH][0-9]+$"));
64 if (rx1.match(key).hasMatch()) {
69 QRegularExpression rx2(QStringLiteral(
"^[0-9]+$"));
70 if (rx2.match(key).hasMatch()) {
85 QFile cacheFile(QStringLiteral(
"%1/%2")
86 .arg(DU::getUserCacheDir().absolutePath(),
name()));
90 auto const writeCache = [
this,&cacheFile,&moduleVersion]{
91 qDebug() <<
"Writing cache file" << cacheFile.fileName();
92 if (cacheFile.open(QIODevice::WriteOnly)) {
93 QDataStream s(&cacheFile);
94 s.setVersion(QDataStream::Qt_5_15);
96 << QString::number(cacheFormat)
97 << QString::number(QDataStream::Qt_DefaultCompiledVersion);
98 s.setVersion(QDataStream::Qt_DefaultCompiledVersion);
102 if (s.status() == QDataStream::Ok) {
103 qDebug() <<
"Cache file written successfully!";
105 qDebug() <<
"Failed to write cache file! Attempting to remove.";
106 if (cacheFile.remove()) {
107 qDebug() <<
"Removed potentially corrupt cache.";
109 qDebug() <<
"Failed to remove potentially corrupt cache!";
113 qDebug() <<
"Failed to open cache file for writing!";
120 if (cacheFile.open(QIODevice::ReadOnly)) {
121 qDebug() <<
"Reading lexicon cache for module" <<
name() <<
"...";
122 QDataStream s(&cacheFile);
123 s.setVersion(QDataStream::Qt_5_15);
126 qDebug() <<
" module version:" << str;
127 if (str == moduleVersion) {
129 qDebug() <<
" cache version:" << str;
130 bool isNumber =
false;
131 auto const cacheVersion = str.toInt(&isNumber);
132 if (isNumber && cacheVersion <= cacheFormat) {
134 qDebug() <<
" QDataStream version:" << str;
135 auto const dataStreamVersion = str.toInt(&isNumber);
138 <= QDataStream::Qt_DefaultCompiledVersion)
140 auto const resetVersion = cacheVersion >= 4;
141 qDebug() <<
" QDataStream version reset:" << resetVersion;
143 s.setVersion(dataStreamVersion);
145 if (s.status() == QDataStream::Ok) {
146 qDebug() <<
" entries read:" <<
m_entries.size();
150 if (cacheVersion != cacheFormat)
166 qDebug() <<
"Read all entries of lexicon" <<
name();
169 m.setSkipConsecutiveLinks(
true);
170 m.setPosition(sword::TOP);
175 m_entries.append(QString::fromUtf8(m.getKeyText()));
177 }
while (!m.popError());
182 }
while (!m.popError());
185 m.setPosition(sword::TOP);
186 m.setSkipConsecutiveLinks(
false);
205 if (
auto const match =
206 QRegularExpression(QStringLiteral(
"^([GH]?)0*([0-9]+?)$"))
210 auto const lang = match.capturedView(1);
211 auto const digits = match.capturedView(2);
216 auto numPaddingZeroesRequired = size - digits.size();
220 normalized.reserve(size);
222 normalized.append(lang);
223 while (numPaddingZeroesRequired--)
224 normalized.append(
'0');
225 normalized.append(digits);