From 5fe3b598e6da0fbef6aa1933d6b811c31ae608a6 Mon Sep 17 00:00:00 2001 From: Thomas Kent Date: Fri, 3 Jun 2016 15:10:47 -0500 Subject: [PATCH] Support for semicolon comment delimiter INI style configuration files should support the semicolon ';' character, when it is the first character on the line only, as a comment delimiter. Because the '#' style comments are not allowed in strict MS INI files, this gives an opening for files to be compatible in both and still have comments. --- doc/overview.xml | 5 ++++- src/config_file.cpp | 3 +++ test/parsers_test.cpp | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/overview.xml b/doc/overview.xml index f7de2968c..dae3c808e 100644 --- a/doc/overview.xml +++ b/doc/overview.xml @@ -500,6 +500,9 @@ notify(vm); The # character introduces a comment that spans until the end of the line. + The ; character at the beginning of + a line makes the entire line a comment. + The option names are relative to the section names, so @@ -649,4 +652,4 @@ gui.accessibility.visual_bell=yes sgml-parent-document: ("program_options.xml" "section") sgml-set-face: t End: ---> \ No newline at end of file +--> diff --git a/src/config_file.cpp b/src/config_file.cpp index f2a57b4b8..89a1ea818 100644 --- a/src/config_file.cpp +++ b/src/config_file.cpp @@ -90,6 +90,9 @@ namespace boost { namespace program_options { namespace detail { // strip '#' comments and whitespace if ((n = s.find('#')) != string::npos) s = s.substr(0, n); + // if the first character is a ';' line is a comment + if (!s.empty() && ';' == s.at(0)) + s = ""; s = trim_ws(s); if (!s.empty()) { diff --git a/test/parsers_test.cpp b/test/parsers_test.cpp index cc1bdd3f2..2c1dbcc84 100644 --- a/test/parsers_test.cpp +++ b/test/parsers_test.cpp @@ -211,6 +211,7 @@ void test_config_file(const char* config_file) const char content1[] = " gv1 = 0#asd\n" + "; semi comment\n" "empty_value = \n" "plug3 = 7\n" "b = true\n"