Switch to string view where applicable

PR #22438.
This commit is contained in:
Chocobo1 2025-03-17 19:28:38 +08:00 committed by GitHub
parent 5a4b3b25d3
commit 8d0870c953
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 27 deletions

View file

@ -237,15 +237,15 @@ void WebApplication::translateDocument(QString &data) const
i = data.indexOf(regex, i, &regexMatch);
if (i >= 0)
{
const QString sourceText = regexMatch.captured(1);
const QString context = regexMatch.captured(3);
const QStringView sourceText = regexMatch.capturedView(1);
const QStringView context = regexMatch.capturedView(3);
const QString loadedText = m_translationFileLoaded
? m_translator.translate(context.toUtf8().constData(), sourceText.toUtf8().constData())
: QString();
// `loadedText` is empty when translation is not provided
// it should fallback to `sourceText`
QString translation = loadedText.isEmpty() ? sourceText : loadedText;
QString translation = loadedText.isEmpty() ? sourceText.toString() : loadedText;
// Escape quotes to workaround issues with HTML attributes
// FIXME: this is a dirty workaround to deal with broken translation strings: