From c99e24f2c19d800c70d29a9d7fd386a62d9477c5 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 17 Jul 2023 21:57:04 -0500 Subject: [PATCH] Ignore comment character if it appears in quotes --- wxdata/include/scwx/gr/placefile.hpp | 4 ++-- wxdata/source/scwx/gr/placefile.cpp | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/wxdata/include/scwx/gr/placefile.hpp b/wxdata/include/scwx/gr/placefile.hpp index 33b7fff5..c7f1335a 100644 --- a/wxdata/include/scwx/gr/placefile.hpp +++ b/wxdata/include/scwx/gr/placefile.hpp @@ -33,7 +33,7 @@ public: Placefile(Placefile&&) noexcept; Placefile& operator=(Placefile&&) noexcept; - bool IsValid() const; + bool IsValid() const; static std::shared_ptr Load(const std::string& filename); static std::shared_ptr Load(std::istream& is); @@ -43,5 +43,5 @@ private: std::unique_ptr p; }; -} // namespace common +} // namespace gr } // namespace scwx diff --git a/wxdata/source/scwx/gr/placefile.cpp b/wxdata/source/scwx/gr/placefile.cpp index 3fbe1f08..4c4fdc7f 100644 --- a/wxdata/source/scwx/gr/placefile.cpp +++ b/wxdata/source/scwx/gr/placefile.cpp @@ -110,11 +110,20 @@ std::shared_ptr Placefile::Load(std::istream& is) while (scwx::util::getline(is, line)) { // Find position of comment (;) - std::size_t lineEnd = line.find(';'); - if (lineEnd == std::string::npos) + bool inQuotes = false; + for (std::size_t i = 0; i < line.size(); ++i) { - // Remove comment - line.erase(lineEnd); + if (!inQuotes && line[i] == ';') + { + // Remove comment + line.erase(i); + break; + } + else if (line[i] == '"') + { + // Toggle quote state + inQuotes = !inQuotes; + } } // Remove extra spacing from line