From 938a61d87166eab786d3ba4f1e1f4360179abd7d Mon Sep 17 00:00:00 2001 From: Miroslav Stoyanov <30537612+mkstoyanov@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:01:10 -0500 Subject: [PATCH] allow inlined comments in the file (#744) allow inline comments in the input files --- src/asgard_program_options.cpp | 3 +++ src/asgard_program_options_tests.cpp | 5 +++++ testing/test_input2.txt | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/asgard_program_options.cpp b/src/asgard_program_options.cpp index 7c81d7170..e9ae78df6 100644 --- a/src/asgard_program_options.cpp +++ b/src/asgard_program_options.cpp @@ -625,6 +625,9 @@ void prog_opts::process_file(std::string_view const &exec_name) while (std::isspace(static_cast(s[be]))) be++; std::string::size_type en = s.size() - 1; + std::string::size_type sharp = s.find('#'); + if (sharp < s.size()) + en = sharp - 1; while (en > be and std::isspace(static_cast(s[en]))) en--; return s.substr(be, en - be + 1); diff --git a/src/asgard_program_options_tests.cpp b/src/asgard_program_options_tests.cpp index 854f2dbc2..eb2dd53bc 100644 --- a/src/asgard_program_options_tests.cpp +++ b/src/asgard_program_options_tests.cpp @@ -338,6 +338,11 @@ TEST_CASE("input file processing", "[file i/o]") static_assert(std::is_same_v>); REQUIRE(!!name); REQUIRE(name.value() == "some-name test"); + + auto nu = prog.file_value("var nu"); + static_assert(std::is_same_v>); + REQUIRE(!!nu); + REQUIRE(nu.value() == 314); } SECTION("test_input1.txt -- direct ") diff --git a/testing/test_input2.txt b/testing/test_input2.txt index 34ddc1215..d94637cb3 100644 --- a/testing/test_input2.txt +++ b/testing/test_input2.txt @@ -7,3 +7,5 @@ v_thermal : 0.5 half percent : 5.E-3 extra name : some-name test + # line above has white spaces # # + var nu : 314 # inlined comment