summaryrefslogtreecommitdiff
path: root/HighlightingRules.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-09-26 23:24:28 +0200
committerChristoph Berg <myon@debian.org>2026-09-26 23:24:28 +0200
commit69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch)
treeebc98370a697a9bbd6b973a14fa5113c475c6db7 /HighlightingRules.cpp
parent3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff)
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg' with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'HighlightingRules.cpp')
-rw-r--r--HighlightingRules.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/HighlightingRules.cpp b/HighlightingRules.cpp
new file mode 100644
index 00000000..495fee42
--- /dev/null
+++ b/HighlightingRules.cpp
@@ -0,0 +1,53 @@
+#include "HighlightingRules.hpp"
+
+#include <QRegularExpression>
+#include <QStringList>
+
+namespace HighlightingRules
+{
+ namespace
+ {
+ // True if `token` + `delimiter` occurs in `entries` starting at the
+ // beginning of the string or right after a previous entry's own ','
+ // or ';' terminator -- so an unrelated, longer configured entry (e.g.
+ // "AK1ABC,") can't spuriously match as a substring tail of a lookup
+ // for "K1ABC", and so the first entry in a list matches even when (per
+ // the documented format, e.g. "VK;ZL;T88;") it has no delimiter before it.
+ bool containsDelimitedToken (QString const& entries, QString const& token, QChar delimiter)
+ {
+ QRegularExpression const re (QStringLiteral ("(?:^|[,;])")
+ + QRegularExpression::escape (token) + QRegularExpression::escape (delimiter));
+ return re.match (entries).hasMatch ();
+ }
+ }
+
+ bool matchesDirectionalCall (QString const& configured_entries,
+ QString const& directional_call)
+ {
+ auto const wanted = directional_call.trimmed ();
+ if (wanted.isEmpty ()) return false;
+
+ for (auto const& entry : configured_entries.split (','))
+ {
+ if (entry.trimmed ().compare (wanted, Qt::CaseInsensitive) == 0) return true;
+ }
+
+ return false;
+ }
+
+ bool matchesCallsignPrefix (QString const& configured_entries, QString const& call)
+ {
+ if (call.size () < 3) return false;
+
+ bool const matched =
+ containsDelimitedToken (configured_entries, call, ',')
+ || containsDelimitedToken (configured_entries, call.left (3), ';')
+ || containsDelimitedToken (configured_entries, call.left (2), ';')
+ || (containsDelimitedToken (configured_entries, call.left (1), ';') && call.at (1).isDigit ())
+ || containsDelimitedToken (configured_entries, call.left (1) + "*", ';');
+ if (!matched) return false;
+
+ return !configured_entries.contains ("!" + call.left (2) + "!")
+ && !configured_entries.contains ("!" + call.left (3) + "!");
+ }
+}