66 module.setPosition(sword::TOP);
68 QString key = QString::fromUtf8(module.getKeyText());
69 QRegularExpression rx1(QStringLiteral(
"^[GH][0-9]+$"));
70 if (rx1.match(key).hasMatch()) {
75 QRegularExpression rx2(QStringLiteral(
"^[0-9]+$"));
76 if (rx2.match(key).hasMatch()) {
91 QFile cacheFile(QStringLiteral(
"%1/%2")
92 .arg(DU::getUserCacheDir().absolutePath(),
name()));
96 auto const writeCache = [
this,&cacheFile,&moduleVersion]{
97 qDebug() <<
"Writing cache file" << cacheFile.fileName();
98 if (cacheFile.open(QIODevice::WriteOnly)) {
99 QDataStream s(&cacheFile);
100 s.setVersion(QDataStream::Qt_5_15);
102 << QString::number(cacheFormat)
103 << QString::number(QDataStream::Qt_DefaultCompiledVersion);
104 s.setVersion(QDataStream::Qt_DefaultCompiledVersion);
108 if (s.status() == QDataStream::Ok) {
109 qDebug() <<
"Cache file written successfully!";
111 qDebug() <<
"Failed to write cache file! Attempting to remove.";
112 if (cacheFile.remove()) {
113 qDebug() <<
"Removed potentially corrupt cache.";
115 qDebug() <<
"Failed to remove potentially corrupt cache!";
119 qDebug() <<
"Failed to open cache file for writing!";
126 if (cacheFile.open(QIODevice::ReadOnly)) {
127 qDebug() <<
"Reading lexicon cache for module" <<
name() <<
"...";
128 QDataStream s(&cacheFile);
129 s.setVersion(QDataStream::Qt_5_15);
132 qDebug() <<
" module version:" << str;
133 if (str == moduleVersion) {
135 qDebug() <<
" cache version:" << str;
136 bool isNumber =
false;
137 auto const cacheVersion = str.toInt(&isNumber);
138 if (isNumber && cacheVersion <= cacheFormat) {
140 qDebug() <<
" QDataStream version:" << str;
141 auto const dataStreamVersion = str.toInt(&isNumber);
144 <= QDataStream::Qt_DefaultCompiledVersion)
146 auto const resetVersion = cacheVersion >= 4;
147 qDebug() <<
" QDataStream version reset:" << resetVersion;
149 s.setVersion(dataStreamVersion);
151 if (s.status() == QDataStream::Ok) {
152 qDebug() <<
" entries read:" <<
m_entries.size();
156 if (cacheVersion != cacheFormat)
172 qDebug() <<
"Read all entries of lexicon" <<
name();
175 m.setSkipConsecutiveLinks(
true);
176 m.setPosition(sword::TOP);
181 m_entries.append(QString::fromUtf8(m.getKeyText()));
183 }
while (!m.popError());
191 }
while (!m.popError());
194 m.setPosition(sword::TOP);
195 m.setSkipConsecutiveLinks(
false);
214 if (
auto const match =
215 QRegularExpression(QStringLiteral(
"^([GH]?)0*([0-9]+?)$"))
219 auto const lang = match.capturedView(1);
220 auto const digits = match.capturedView(2);
225 auto numPaddingZeroesRequired = size - digits.size();
229 normalized.reserve(size);
231 normalized.append(lang);
232 while (numPaddingZeroesRequired--)
233 normalized.append(
'0');
234 normalized.append(digits);