Skip to content
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
1 change: 1 addition & 0 deletions test/parsers_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ 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.

"empty_value = \n"
"plug3 = 7\n"
"b = true\n"
Expand Down