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 /src/m_im | |
| 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
Diffstat (limited to 'src/m_im')
| -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 |
3 files changed, 22 insertions, 20 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({})); |
