From d3cf9cf8e27e4e39acc2b407887c9429e8fbcb8a Mon Sep 17 00:00:00 2001 From: LeoKle Date: Sun, 10 Mar 2024 21:55:34 +0100 Subject: [PATCH] fix airport creation using airport name depending on the available EuroScope data, airports names do not only consists of the airport icao, but may also include the name --- helper/String.h | 32 ++++++++++++++++++++++++++++++++ vACDM.cpp | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/helper/String.h b/helper/String.h index 783cea8..feb5280 100644 --- a/helper/String.h +++ b/helper/String.h @@ -10,6 +10,7 @@ #include #include +#include namespace vacdm { namespace helper { @@ -83,6 +84,37 @@ namespace vacdm { return value.substr(begin, range); } + + /** + * @brief find the first occurrence of a 4-letter ICAO code + * @param[in] value the string to find the ICAO in + * @return the ICAO or "" if none was found + */ + static auto findIcao(std::string input) -> std::string { +#pragma warning(disable : 4244) + std::transform(input.begin(), input.end(), input.begin(), + ::toupper); +#pragma warning(default : 4244) + + // Find the first occurrence of a 4-letter ICAO code + std::size_t found = + input.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + while (found != std::string::npos) { + // Check if the substring starting from the found position is + // 4 characters long + if (input.substr(found, 4).length() == 4) { + return input.substr(found, 4); + } + + // Continue searching for the next uppercase letter + found = input.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ", + found + 1); + } + + // Return an empty string if no valid ICAO code is found + return ""; + } }; } } diff --git a/vACDM.cpp b/vACDM.cpp index ee04255..9223e10 100644 --- a/vACDM.cpp +++ b/vACDM.cpp @@ -112,7 +112,8 @@ void vACDM::OnAirportRunwayActivityChanged() { EuroScopePlugIn::CSectorElement rwy; for (rwy = this->SectorFileElementSelectFirst(EuroScopePlugIn::SECTOR_ELEMENT_RUNWAY); true == rwy.IsValid(); rwy = this->SectorFileElementSelectNext(rwy, EuroScopePlugIn::SECTOR_ELEMENT_RUNWAY)) { - auto airport = trim(rwy.GetAirportName()); + + auto airport = helper::String::findIcao(trim(rwy.GetAirportName())); if (true == rwy.IsElementActive(true, 0)) { if (m_activeRunways.find(airport) == m_activeRunways.end())