Skip to content

Commit

Permalink
Added capitalization function for waypoint names.
Browse files Browse the repository at this point in the history
  • Loading branch information
albar965 committed Aug 25, 2024
1 parent 7417791 commit 453e8e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/fs/util/fsutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace util {
// Closed airport by name
const static QRegularExpression REGEXP_CLOSED(QLatin1String("(\\[X\\]|\\bCLSD\\b|\\bCLOSED\\b)"));
const static QRegularExpression REGEXP_DIGIT("\\d");
const static QRegularExpression REGEXP_WAYPOINT_DME("(\\w+) \\((\\w+) ([\\d\\.]+) DME\\)");
const static QRegularExpression REGEXP_WHITESPACE("\\s");

/* ICAO speed and altitude matches */
Expand Down Expand Up @@ -459,6 +460,25 @@ bool isNameMilitary(QString airportName)
return false;
}

QString capWaypointNameString(const QString& ident, const QString& name, bool emptyIfEqual)
{
if(ident == name)
return emptyIfEqual ? QString() : name;
else
{
if(name.contains('('))
{
QRegularExpressionMatch match = REGEXP_WAYPOINT_DME.match(name);
if(match.hasMatch())
// Special case "IKR138012 (KRE 11.2 DME)"
return match.captured(1) % " (" % match.captured(2).toUpper() % ' ' + match.captured(3) % " DME)";

}
}

return capNavString(name);
}

QString capNavString(const QString& str)
{
if(str.contains(REGEXP_DIGIT) && !str.contains(REGEXP_WHITESPACE))
Expand All @@ -482,8 +502,7 @@ QString capNavString(const QString& str)
"TCA", "MCTR", "VFR", "IFR", "DFS", "TNA", "CAE", "LANTA",
"TSRA" "AFB", "OCA", "ARB", "MCAS", "NAS", "NOLF", "NS", "NAWS", "USAF", "TMAD", "CON", "ATS", "MTMA",
"TRSA", "SFB", "AAF", "DC", "CGAS", "RT", "ASPC", "UAC", "LTA",
"I", "II", "III", "IV", "V", "VI"
});
"I", "II", "III", "IV", "V", "VI", "NM"});

return atools::capString(str, FORCE_UPPER).trimmed();
}
Expand Down
3 changes: 3 additions & 0 deletions src/fs/util/fsutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ bool isNameClosed(const QString& airportName);
/* Capitalize any string ignoring aviation acronyms */
QString capNavString(const QString& str);

/* Capitalize only if ident not equal to name. Used for waypoint names. */
QString capWaypointNameString(const QString& ident, const QString& name, bool emptyIfEqual);

/* Capitalize airport name making special designators (AFB, ...) upper case */
QString capAirportName(const QString& str);

Expand Down

0 comments on commit 453e8e6

Please # to comment.