Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for semicolon comment delimiter #22

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
3 changes: 3 additions & 0 deletions doc/overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ notify(vm);
<listitem><para>The <literal>#</literal> character introduces a
comment that spans until the end of the line.</para>
</listitem>
<listitem><para>The <literal>;</literal> character at the beginning of
a line makes the entire line a comment.</para>
</listitem>
</itemizedlist>

<para>The option names are relative to the section names, so
Expand Down
8 changes: 7 additions & 1 deletion src/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ namespace boost { namespace program_options { namespace detail {
// strip '#' comments and whitespace
if ((n = s.find('#')) != string::npos)
s = s.substr(0, n);
s = trim_ws(s);
// if the first character is a ';' line is a comment
if (!s.empty() && ';' == *s.begin()) {
s = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just do continue; here?

}
else {
s = trim_ws(s);
}

if (!s.empty()) {
// Handle section name
Expand Down
2 changes: 2 additions & 0 deletions test/config_test.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
gv1 = 0#asd
; semi test
; semi_value = 9
empty_value =
plug3 = 7
b = true
Expand Down
5 changes: 3 additions & 2 deletions test/parsers_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ void test_config_file(const char* config_file)
desc.add_options()
("gv1", new untyped_value)
("gv2", new untyped_value)
("semi_value", new untyped_value)
("empty_value", new untyped_value)
("plug*", new untyped_value)
("m1.v1", new untyped_value)
Expand All @@ -267,6 +268,8 @@ void test_config_file(const char* config_file)

const char content1[] =
" gv1 = 0#asd\n"
"; semi comment\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A also want to see a commented-out line which has an assignment, and a check to ensure the value is not assigned.

"; semi_value = 9\n"
"empty_value = \n"
"plug3 = 7\n"
"b = true\n"
Expand Down Expand Up @@ -383,6 +386,4 @@ int main(int, char* av[])
test_config_file(av[1]);
test_environment();
test_unregistered();
return 0;
}