diff options
| author | saturneric <[email protected]> | 2026-10-24 11:00:29 +0200 |
|---|---|---|
| committer | saturneric <[email protected]> | 2026-10-24 11:00:29 +0200 |
| commit | acd8cfc36bc2ddb9584f8a27b364f43e5cc24af3 (patch) | |
| tree | ab1936b700b9156d9dce89a0ce67c9f9239ed953 | |
| parent | refactor(email): use Qt string literal operators (diff) | |
| download | modules-acd8cfc36bc2ddb9584f8a27b364f43e5cc24af3.tar.gz modules-acd8cfc36bc2ddb9584f8a27b364f43e5cc24af3.zip | |
refactor: use Qt string literal operators in modules
- replace QStringLiteral with u""_s and QLatin1String with ""_L1 in the
im, key server sync, pgp inspect and version check modules
- spell non-literal Latin-1 views as QLatin1StringView
- import Qt::StringLiterals per file, as modules have no host PCH
| -rw-r--r-- | src/m_im/ImCodec.cpp | 16 | ||||
| -rw-r--r-- | src/m_im/ImToken.cpp | 4 | ||||
| -rw-r--r-- | src/m_im/test/ImTokenTest.cpp | 22 | ||||
| -rw-r--r-- | src/m_key_server_sync/KeyServerBatchLogic.cpp | 6 | ||||
| -rw-r--r-- | src/m_key_server_sync/KeyServerList.cpp | 5 | ||||
| -rw-r--r-- | src/m_key_server_sync/KeyServerSyncModule.cpp | 7 | ||||
| -rw-r--r-- | src/m_pgp_inspect/PGPInspectDialog.cpp | 7 | ||||
| -rw-r--r-- | src/m_pgp_inspect/PGPInspectModel.cpp | 7 | ||||
| -rw-r--r-- | src/m_ver_check/SoftwareVersion.cpp | 2 | ||||
| -rw-r--r-- | src/m_ver_check/Utils.cpp | 12 |
10 files changed, 49 insertions, 39 deletions
diff --git a/src/m_im/ImCodec.cpp b/src/m_im/ImCodec.cpp index 0dc5d82..fa36e2e 100644 --- a/src/m_im/ImCodec.cpp +++ b/src/m_im/ImCodec.cpp @@ -36,6 +36,8 @@ #include "GFModuleTr.h" #include "ImToken.h" +using namespace Qt::StringLiterals; + namespace ImCodec { namespace { @@ -55,7 +57,7 @@ auto BookCard(const QString& phrase, qsizetype payload, qsizetype token_len) fields.append(QJsonArray{k, v}); }; - add(GTrC::tr("Encoding"), QStringLiteral("Base58 (Bitcoin/IPFS)")); + add(GTrC::tr("Encoding"), u"Base58 (Bitcoin/IPFS)"_s); add(GTrC::tr("Container Format"), QString("v%1").arg(ImToken::FormatVersion())); add(GTrC::tr("Message Book"), @@ -83,19 +85,17 @@ auto BookCard(const QString& phrase, qsizetype payload, qsizetype token_len) QString("+%1%").arg((ratio * 100.0) - 100.0, 0, 'f', 0)); } - return QJsonObject{ - {QStringLiteral("title"), GTrC::tr("Instant Messaging")}, - {QStringLiteral("status"), - configured ? QStringLiteral("ok") : QStringLiteral("warn")}, - {QStringLiteral("fields"), fields}}; + return QJsonObject{{u"title"_s, GTrC::tr("Instant Messaging")}, + {u"status"_s, configured ? u"ok"_s : u"warn"_s}, + {u"fields"_s, fields}}; } auto CardsJson(const QJsonObject& card) -> QString { const QJsonObject payload{ - {QStringLiteral("description"), + {u"description"_s, GTrC::tr( "An Instant Messaging section followed by the OpenPGP result.")}, - {QStringLiteral("cards"), QJsonArray{card}}}; + {u"cards"_s, QJsonArray{card}}}; return QString::fromUtf8( QJsonDocument(payload).toJson(QJsonDocument::Compact)); } diff --git a/src/m_im/ImToken.cpp b/src/m_im/ImToken.cpp index 031a286..5b5fa24 100644 --- a/src/m_im/ImToken.cpp +++ b/src/m_im/ImToken.cpp @@ -41,6 +41,8 @@ #include <cstring> #include <string_view> +using namespace Qt::StringLiterals; + // The token format, moved out of the Host's core unchanged: the wire is a // contract between every copy of GpgFrontend, so not one byte of what Encode() // writes or Decode() accepts may differ from what the core used to do. The @@ -588,7 +590,7 @@ auto BuildPermutation(const QByteArray& material, int m) -> QList<int> { // What it does buy us is local: ordinary text now stops at its first space or // punctuation mark instead of reaching the O(n^2) decoder and the 128 MiB KDF. auto Normalize(const QString& text, QString& compact) -> bool { - if (text.contains(QLatin1String("-----BEGIN PGP"))) return false; + if (text.contains("-----BEGIN PGP"_L1)) return false; compact.clear(); compact.reserve(std::min<qsizetype>(text.size(), kMaxTokenChars)); diff --git a/src/m_im/test/ImTokenTest.cpp b/src/m_im/test/ImTokenTest.cpp index 1cb8f72..36dca27 100644 --- a/src/m_im/test/ImTokenTest.cpp +++ b/src/m_im/test/ImTokenTest.cpp @@ -36,6 +36,8 @@ #include "ImToken.h" +using namespace Qt::StringLiterals; + /** * @file ImTokenTest.cpp * @brief The token format, moved out of the core unchanged. These are the @@ -157,7 +159,7 @@ TEST(ImTokenTest, NormalRoundTrip) { ASSERT_FALSE(token.isEmpty()); // Single Base58 word (alphanumeric minus 0 O I l), no markdown/link chars. EXPECT_TRUE(QRegularExpression(QRegularExpression::anchoredPattern( - QStringLiteral("[1-9A-HJ-NP-Za-km-z]+"))) + u"[1-9A-HJ-NP-Za-km-z]+"_s)) .match(token) .hasMatch()); @@ -185,7 +187,7 @@ TEST(ImTokenTest, DecodeRejectsArmoredMessage) { TEST(ImTokenTest, DecodeToleratesWhitespace) { const QByteArray blob = PgpLikeBlob(); auto token = Encode(blob); - token.insert(token.size() / 2, QStringLiteral("\n ")); + token.insert(token.size() / 2, u"\n "_s); const auto r = Decode(token); EXPECT_TRUE(r.ok); @@ -246,7 +248,7 @@ TEST(ImTokenTest, FormatVersionIsStable) { } TEST(ImTokenTest, ShortInputIsRejected) { - EXPECT_FALSE(Decode(QStringLiteral("hi")).ok); + EXPECT_FALSE(Decode(u"hi"_s).ok); EXPECT_FALSE(Decode(QString(37, 'z')).ok); } @@ -264,7 +266,7 @@ TEST(ImTokenTest, NonBase58InputIsRejected) { TEST(ImTokenTest, PreFilterIsFastOnLargeInput) { ScopedKdfCost cost(ImToken::DefaultKdfCost()); - const QString prose = QStringLiteral("the quick brown fox. ").repeated(50000); + const QString prose = u"the quick brown fox. "_s.repeated(50000); const QString base58_only = QString(qsizetype{1024} * 1024, 'z'); QElapsedTimer timer; @@ -297,9 +299,8 @@ TEST(ImTokenTest, MaxPayloadBytesIsPinned) { // across phrases, and short enough to compare by eye. TEST(ImTokenTest, BookFingerprintIdentifiesBook) { const auto fpr = ImToken::BookFingerprintOf(kPhrase); - EXPECT_TRUE(QRegularExpression(QStringLiteral("^[0-9A-F]{4}-[0-9A-F]{4}$")) - .match(fpr) - .hasMatch()); + EXPECT_TRUE( + QRegularExpression(u"^[0-9A-F]{4}-[0-9A-F]{4}$"_s).match(fpr).hasMatch()); EXPECT_EQ(ImToken::BookFingerprintOf(kPhrase), fpr); const auto other = ImToken::BookFingerprintOf("a completely different one"); @@ -309,13 +310,12 @@ TEST(ImTokenTest, BookFingerprintIdentifiesBook) { EXPECT_NE(def, other); // Whitespace around a phrase is not part of it. - EXPECT_EQ(ImToken::BookFingerprintOf(QStringLiteral(" ") + kPhrase + " "), - fpr); + EXPECT_EQ(ImToken::BookFingerprintOf(u" "_s + kPhrase + " "), fpr); } // Every copy of GpgFrontend builds the same default book. TEST(ImTokenTest, DefaultBookIsPinned) { - EXPECT_EQ(ImToken::BookFingerprintOf({}), QStringLiteral("9138-57AC")); + EXPECT_EQ(ImToken::BookFingerprintOf({}), u"9138-57AC"_s); } TEST(ImTokenTest, GeneratePhraseIsLongAndUnique) { @@ -325,7 +325,7 @@ TEST(ImTokenTest, GeneratePhraseIsLongAndUnique) { EXPECT_EQ(b.size(), 256); EXPECT_NE(a, b); EXPECT_TRUE(QRegularExpression(QRegularExpression::anchoredPattern( - QStringLiteral("[1-9A-HJ-NP-Za-km-z]+"))) + u"[1-9A-HJ-NP-Za-km-z]+"_s)) .match(a) .hasMatch()); EXPECT_NE(ImToken::BookFingerprintOf(a), ImToken::BookFingerprintOf({})); diff --git a/src/m_key_server_sync/KeyServerBatchLogic.cpp b/src/m_key_server_sync/KeyServerBatchLogic.cpp index 18588eb..e1ae807 100644 --- a/src/m_key_server_sync/KeyServerBatchLogic.cpp +++ b/src/m_key_server_sync/KeyServerBatchLogic.cpp @@ -33,6 +33,8 @@ #include "GFModuleTr.h" +using namespace Qt::StringLiterals; + namespace KeyServerBatchLogic { namespace { @@ -40,9 +42,9 @@ namespace { /// The failures, one per line, under the headline. auto WithFailures(QString headline, const QStringList& failures) -> QString { if (failures.isEmpty()) return headline; - headline += QStringLiteral("\n\n"); + headline += u"\n\n"_s; headline += GTrC::tr("Failed:"); - for (const auto& f : failures) headline += QStringLiteral("\n") + f; + for (const auto& f : failures) headline += u"\n"_s + f; return headline; } diff --git a/src/m_key_server_sync/KeyServerList.cpp b/src/m_key_server_sync/KeyServerList.cpp index 160d57c..027dff5 100644 --- a/src/m_key_server_sync/KeyServerList.cpp +++ b/src/m_key_server_sync/KeyServerList.cpp @@ -36,6 +36,8 @@ #include "GFModule.h" #include "GFSDKUI.h" +using namespace Qt::StringLiterals; + namespace { // Relative: the Host places them in this module's own settings group, which @@ -126,8 +128,7 @@ auto KeyServerEntry::ToJson() const -> QJsonObject { {"url", url}, {"hkp", hkp}, {"vks", vks}, - {"state", - verified ? QStringLiteral("verified") : QStringLiteral("unverified")}, + {"state", verified ? u"verified"_s : u"unverified"_s}, {"last_tested", last_tested.isValid() ? last_tested.toUTC().toString(Qt::ISODate) : QString()}, diff --git a/src/m_key_server_sync/KeyServerSyncModule.cpp b/src/m_key_server_sync/KeyServerSyncModule.cpp index f7ba7f4..672862e 100644 --- a/src/m_key_server_sync/KeyServerSyncModule.cpp +++ b/src/m_key_server_sync/KeyServerSyncModule.cpp @@ -46,6 +46,8 @@ #include "SearchKeyDialog.h" #include "VKSInterface.h" +using namespace Qt::StringLiterals; + namespace { using Severity = gf::cmd::host::AppMessage::Severity; @@ -224,8 +226,7 @@ class KeyServerBatch : public QObject { Schedule(); }, [this, key](const QString& error, const QString&) { - failures_.append( - QStringLiteral("%1: %2").arg(key.fingerprint, error)); + failures_.append(u"%1: %2"_s.arg(key.fingerprint, error)); Schedule(); }, this); @@ -247,7 +248,7 @@ class KeyServerBatch : public QObject { Schedule(); }; const auto failed = [this, key](const QString& error) { - failures_.append(QStringLiteral("%1: %2").arg(key.fingerprint, error)); + failures_.append(u"%1: %2"_s.arg(key.fingerprint, error)); Schedule(); }; if (route_.vks) { diff --git a/src/m_pgp_inspect/PGPInspectDialog.cpp b/src/m_pgp_inspect/PGPInspectDialog.cpp index 27d83fb..dbee47b 100644 --- a/src/m_pgp_inspect/PGPInspectDialog.cpp +++ b/src/m_pgp_inspect/PGPInspectDialog.cpp @@ -41,6 +41,8 @@ #include "GFModuleTr.h" +using namespace Qt::StringLiterals; + namespace { /// Which column holds what. Packet rows use the first only; a field row puts @@ -164,7 +166,7 @@ void PGPInspectDialog::render_document() { } add_fields(item, facts); - if (block.has_armor && block.armor.crc24 == QLatin1String("mismatch")) { + if (block.has_armor && block.armor.crc24 == "mismatch"_L1) { item->setForeground(kLabelColumn, QBrush(QColor(GFUIThemeColorForRole( GFModuleSdkContext(), GF_UI_COLOR_DANGER)))); @@ -185,8 +187,7 @@ void PGPInspectDialog::render_document() { auto summary = GTrC::tr("%1, %2, %n packet(s)", nullptr, packet_count) .arg(document_.format, HumanSize(size_)); if (!document_.errors.isEmpty()) { - summary += - QLatin1String(" - ") + document_.errors.join(QLatin1String("; ")); + summary += " - "_L1 + document_.errors.join("; "_L1); } summary_label_->setText(summary); } diff --git a/src/m_pgp_inspect/PGPInspectModel.cpp b/src/m_pgp_inspect/PGPInspectModel.cpp index 221b106..7c01254 100644 --- a/src/m_pgp_inspect/PGPInspectModel.cpp +++ b/src/m_pgp_inspect/PGPInspectModel.cpp @@ -36,6 +36,8 @@ #include "GFModuleTr.h" +using namespace Qt::StringLiterals; + namespace { auto ParseFields(const QJsonValue& value) -> QList<PGPInspectField> { @@ -166,8 +168,7 @@ auto PGPInspectPacketSummary(const PGPInspectPacket& packet, int index) summary += QString(" @0x%1").arg(packet.offset, 4, 16, QChar('0')); summary += GTrC::tr(" %1 B").arg(packet.header_length + packet.body_length); - if (packet.length_type != QLatin1String("fixed") && - !packet.length_type.isEmpty()) { + if (packet.length_type != "fixed"_L1 && !packet.length_type.isEmpty()) { summary += QString(" [%1]").arg(packet.length_type); } return summary; @@ -175,7 +176,7 @@ auto PGPInspectPacketSummary(const PGPInspectPacket& packet, int index) auto PGPInspectBlockSummary(const PGPInspectBlock& block, int index) -> QString { - if (block.kind == QLatin1String("cleartext")) { + if (block.kind == "cleartext"_L1) { return GTrC::tr("Block %1: cleartext-signed message").arg(index); } if (block.has_armor) { diff --git a/src/m_ver_check/SoftwareVersion.cpp b/src/m_ver_check/SoftwareVersion.cpp index 2184361..41b9885 100644 --- a/src/m_ver_check/SoftwareVersion.cpp +++ b/src/m_ver_check/SoftwareVersion.cpp @@ -62,7 +62,7 @@ template <typename Enum, std::size_t N> auto ValueOf(const std::array<std::pair<Enum, const char*>, N>& names, const QString& name) -> Enum { for (const auto& [e, n] : names) { - if (name == QLatin1String(n)) return e; + if (name == QLatin1StringView(n)) return e; } return names.front().first; } diff --git a/src/m_ver_check/Utils.cpp b/src/m_ver_check/Utils.cpp index 05352c7..a017e84 100644 --- a/src/m_ver_check/Utils.cpp +++ b/src/m_ver_check/Utils.cpp @@ -33,22 +33,24 @@ #include "ReleaseCheck.h" #include "VersionCheckingModule.h" +using namespace Qt::StringLiterals; + namespace { auto VerdictName(Verdict v) -> QString { switch (v) { case Verdict::kUpdateAvailable: - return QStringLiteral("update_available"); + return u"update_available"_s; case Verdict::kWithdrawnOrUnreleased: - return QStringLiteral("withdrawn_or_unreleased"); + return u"withdrawn_or_unreleased"_s; case Verdict::kUnofficialBuild: - return QStringLiteral("unofficial_build"); + return u"unofficial_build"_s; case Verdict::kUpToDate: - return QStringLiteral("up_to_date"); + return u"up_to_date"_s; case Verdict::kUnknown: break; } - return QStringLiteral("unknown"); + return u"unknown"_s; } } // namespace |
