diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
| commit | 69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch) | |
| tree | ebc98370a697a9bbd6b973a14fa5113c475c6db7 /validators/LiveCQCallsign.cpp | |
| parent | 3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff) | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (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 'validators/LiveCQCallsign.cpp')
| -rw-r--r-- | validators/LiveCQCallsign.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/validators/LiveCQCallsign.cpp b/validators/LiveCQCallsign.cpp new file mode 100644 index 00000000..14f151bf --- /dev/null +++ b/validators/LiveCQCallsign.cpp @@ -0,0 +1,64 @@ +#include "LiveCQCallsign.hpp" + +#include <QStringList> +#include <QtGlobal> + +namespace LiveCQ +{ + bool isValidCallsign (QString const& callsign) + { + auto callsignWithoutMarkers = callsign; + if (callsignWithoutMarkers.contains('.') + || callsignWithoutMarkers.contains('+') + || callsignWithoutMarkers.contains('-') + || callsignWithoutMarkers.contains('?')) { + return false; + } + callsignWithoutMarkers.remove('<'); + callsignWithoutMarkers.remove('>'); + if (callsignWithoutMarkers.length() > 11) { + return false; + } + + auto const parts = callsignWithoutMarkers.split('/'); + auto baseCall = callsignWithoutMarkers; + if (parts.size() > 1) { + baseCall = parts.at(0).length() > parts.at(1).length() + ? parts.at(0) : parts.at(1); + } + baseCall = baseCall.trimmed(); + auto const baseLength = baseCall.length(); + if (baseLength < 3 || baseLength > 8) { + return false; + } + + if (!baseCall.at(0).isLetter() && !baseCall.at(1).isLetter()) { + return false; + } + if (baseCall.at(0) == 'Q' && baseCall.mid(0, 5) != "QU1RK") { + return false; + } + + int digitPosition = 0; + for (int i = 1; i < qMin<int>(static_cast<int> (baseLength), 4); ++i) { + if (baseCall.at(i).isDigit()) { + digitPosition = i; + } + } + if (digitPosition == 0 || digitPosition == baseLength) { + return false; + } + + auto const suffixLength = baseLength - digitPosition - 1; + if (suffixLength < 1 || suffixLength > 4) { + return false; + } + for (int i = digitPosition + 1; i < baseLength; ++i) { + auto const character = baseCall.at(i); + if (character < QChar {'A'} || character > QChar {'Z'}) { + return false; + } + } + return true; + } +} |
