diff --git a/asibfm700_config.h b/asibfm700_config.h index b024d05..8de6841 100644 --- a/asibfm700_config.h +++ b/asibfm700_config.h @@ -108,7 +108,7 @@ public: _inlineComment[_hashes[I]] = rec.inline_comment; }; - [&, this](std::index_sequence) { + [&](std::index_sequence) { (get_comm.template operator()(), ...); }(std::make_index_sequence{}); } @@ -133,48 +133,51 @@ public: fst.close(); // remove possible header (see "save" method) - size_t nskip = 5; - auto lines = std::views::split(buffer, DEFAULT_RECORD_DELIMITER); - if (std::ranges::distance(lines.begin(), lines.end()) >= 5) { - bool head_exists = true; - std::vector tl; - for (auto const& l : lines) { // lines must start with COMMENT_SEQ - tl.emplace_back(mcc::utils::trimSpaces(l)); - if (tl.back().size() >= COMMENT_SEQ.size()) { - auto found = std::ranges::search(tl.back(), COMMENT_SEQ); - if (tl.back().begin() != found.begin()) { - head_exists = false; - break; - } - } else { - head_exists = false; - break; - } - } - if (head_exists) { - // the first and last lines must contain only a comment sequence and possible spaces - if (tl[0].size() != COMMENT_SEQ.size() || tl[3].size() != COMMENT_SEQ.size()) { - head_exists = false; - } else { - if (tl[1] != "# ASTROSIB FM-700 MOUNT CONFIGURATION") { - head_exists = false; - } else { - std::regex rx{ - "# \\(created at " - "20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\.[0-9] " - "UTC\\)"}; - - if (!std::regex_match(std::string{tl[2]}, rx)) { - head_exists = false; - } - } - } - } - - if (!head_exists) { // delete the first N lines - nskip = 0; - } + size_t nskip = headerLines; + if (!std::regex_match(buffer, headerRx)) { + nskip = 0; } + // auto lines = std::views::split(buffer, DEFAULT_RECORD_DELIMITER); + // if (std::ranges::distance(lines.begin(), lines.end()) >= 5) { + // bool head_exists = true; + // std::vector tl; + // for (auto const& l : lines) { // lines must start with COMMENT_SEQ + // tl.emplace_back(mcc::utils::trimSpaces(l)); + // if (tl.back().size() >= COMMENT_SEQ.size()) { + // auto found = std::ranges::search(tl.back(), COMMENT_SEQ); + // if (tl.back().begin() != found.begin()) { + // head_exists = false; + // break; + // } + // } else { + // head_exists = false; + // break; + // } + // } + // if (head_exists) { + // // the first and last lines must contain only a comment sequence and possible spaces + // if (tl[0].size() != COMMENT_SEQ.size() || tl[3].size() != COMMENT_SEQ.size()) { + // head_exists = false; + // } else { + // if (tl[1] != "# ASTROSIB FM-700 MOUNT CONFIGURATION") { + // head_exists = false; + // } else { + // std::regex rx{ + // "# \\(created at " + // "20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\.[0-9] " + // "UTC\\)"}; + + // if (!std::regex_match(std::string{tl[2]}, rx)) { + // head_exists = false; + // } + // } + // } + // } + + // if (!head_exists) { // delete the first N lines + // nskip = 0; + // } + // } ec = base_t::fromCharRange(buffer, nskip); if (!ec) { @@ -275,6 +278,8 @@ public: private: std::filesystem::path _lastConfigPath{}; + static constexpr size_t headerLines = 5; // number of lines in the header + static std::string generateHeader() { std::string s{ @@ -286,6 +291,12 @@ private: std::back_inserter(s), "# (created at {:%FT%T} UTC)\n#\n", std::chrono::round>>(std::chrono::system_clock::now())); + // auto time_stamp = + // std::chrono::round>>(std::chrono::system_clock::now()); + // std::string s = std::format( + // "{0:}{1:}{0:} ASTROSIB FM-700 MOUNT CONFIGURATION{1:}{0:}{1:}{0:} (created at {2:%FT%T} + // UTC){1:}{0:}{1:}", COMMENT_SEQ, rec_delim, time_stamp); + return s; }