diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
| commit | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch) | |
| tree | 1269efa852935b183daae4bb33a58d1b4d2ffb53 /qt_helpers.cpp | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'qt_helpers.cpp')
| -rw-r--r-- | qt_helpers.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/qt_helpers.cpp b/qt_helpers.cpp index a9e5b14d..7f4ceaf8 100644 --- a/qt_helpers.cpp +++ b/qt_helpers.cpp @@ -18,6 +18,33 @@ #include "wsjtx_config.h" #endif +bool serial_port_name_less (QString const& lhs, QString const& rhs) +{ + auto suffix_start = [] (QString const& name) { + auto pos = name.size (); + while (pos && name.at (pos - 1) >= QLatin1Char {'0'} + && name.at (pos - 1) <= QLatin1Char {'9'}) --pos; + return pos; + }; + auto const lhs_start = suffix_start (lhs); + auto const rhs_start = suffix_start (rhs); + auto const prefix_order = lhs.leftRef (lhs_start).compare (rhs.leftRef (rhs_start)); + if (prefix_order) return prefix_order < 0; + if (lhs_start == lhs.size () || rhs_start == rhs.size ()) return lhs < rhs; + + auto significant_digits = [] (QString const& name, int pos) { + while (pos < name.size () && name.at (pos) == QLatin1Char {'0'}) ++pos; + return name.midRef (pos); + }; + auto const lhs_number = significant_digits (lhs, lhs_start); + auto const rhs_number = significant_digits (rhs, rhs_start); + // Comparing digits avoids overflow for long device identifiers. + if (lhs_number.size () != rhs_number.size ()) return lhs_number.size () < rhs_number.size (); + auto const number_order = lhs_number.compare (rhs_number); + if (number_order) return number_order < 0; + return lhs < rhs; +} + QString font_as_stylesheet (QFont const& font) { QString font_weight; |
