mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 01:03:08 -07:00
Replace QRegExp with QRegularExpression
Revise `static` keyword usage, static is added to frequently used instances.
This commit is contained in:
parent
c22e6b4502
commit
09f759355f
14 changed files with 72 additions and 63 deletions
|
@ -97,8 +97,8 @@ namespace
|
|||
|
||||
void translateDocument(const QString &locale, QString &data)
|
||||
{
|
||||
const QRegExp regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])");
|
||||
const QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?");
|
||||
const QRegularExpression regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])");
|
||||
const QRegularExpression mnemonic("\\(?&([a-zA-Z]?\\))?");
|
||||
|
||||
const bool isTranslationNeeded = !locale.startsWith("en")
|
||||
|| locale.startsWith("en_AU") || locale.startsWith("en_GB");
|
||||
|
@ -106,23 +106,24 @@ namespace
|
|||
int i = 0;
|
||||
bool found = true;
|
||||
while (i < data.size() && found) {
|
||||
i = regex.indexIn(data, i);
|
||||
QRegularExpressionMatch regexMatch;
|
||||
i = data.indexOf(regex, i, ®exMatch);
|
||||
if (i >= 0) {
|
||||
const QString word = regex.cap(1);
|
||||
const QString context = regex.cap(4);
|
||||
const QString word = regexMatch.captured(1);
|
||||
const QString context = regexMatch.captured(4);
|
||||
|
||||
QString translation = isTranslationNeeded
|
||||
? qApp->translate(context.toUtf8().constData(), word.toUtf8().constData(), nullptr, 1)
|
||||
: word;
|
||||
|
||||
// Remove keyboard shortcuts
|
||||
translation.replace(mnemonic, "");
|
||||
translation.remove(mnemonic);
|
||||
|
||||
// Use HTML code for quotes to prevent issues with JS
|
||||
translation.replace('\'', "'");
|
||||
translation.replace('\"', """);
|
||||
|
||||
data.replace(i, regex.matchedLength(), translation);
|
||||
data.replace(i, regexMatch.capturedLength(), translation);
|
||||
i += translation.length();
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue