forked from aethersdr/AetherSDR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrequencyEntryParser.cpp
More file actions
36 lines (30 loc) · 1.12 KB
/
Copy pathFrequencyEntryParser.cpp
File metadata and controls
36 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "FrequencyEntryParser.h"
namespace AetherSDR::FrequencyEntryParser {
QString normalizedMhzText(const QString& text)
{
QString clean = text.trimmed();
const int firstDot = clean.indexOf(QLatin1Char('.'));
if (firstDot >= 0) {
const QString beforeDot = clean.left(firstDot);
const QString afterDot = clean.mid(firstDot + 1).remove(QLatin1Char('.'));
clean = beforeDot + QLatin1Char('.') + afterDot;
}
return clean;
}
bool isExplicitMhzEntry(const QString& rawText, const QString& normalizedText)
{
const int dot = normalizedText.indexOf(QLatin1Char('.'));
if (dot < 0) {
return false;
}
// Display-style entries are already MHz.kHz.Hz, even when the current
// slice is not yet on an XVTR/high-frequency band.
if (rawText.count(QLatin1Char('.')) >= 2) {
return true;
}
// Single-dot entries with a normal MHz field are explicit MHz. Preserve
// the historic HF shortcut where `14225.0` means 14.225 MHz by treating
// five-plus leading digits as kHz-style input.
return dot <= 4;
}
} // namespace AetherSDR::FrequencyEntryParser