Skip to content

Commit

Permalink
fix airport creation using airport name
Browse files Browse the repository at this point in the history
depending on the available EuroScope data, airports names do not only consists of the airport icao, but may also include the name
  • Loading branch information
LeoKle committed Mar 10, 2024
1 parent 099b6b1 commit d3cf9cf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 32 additions & 0 deletions helper/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <string>
#include <vector>
#include <algorithm>

namespace vacdm {
namespace helper {
Expand Down Expand Up @@ -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 "";
}
};
}
}
3 changes: 2 additions & 1 deletion vACDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit d3cf9cf

Please sign in to comment.