Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70666 - in trunk: boost/property_tree libs/property_tree/test
From: sebastian.redl_at_[hidden]
Date: 2011-03-28 09:44:16


Author: cornedbee
Date: 2011-03-28 09:44:16 EDT (Mon, 28 Mar 2011)
New Revision: 70666
URL: http://svn.boost.org/trac/boost/changeset/70666

Log:
Allow the use of # as a comment character in the PTree INI parser.
Text files modified:
   trunk/boost/property_tree/ini_parser.hpp | 3 ++-
   trunk/libs/property_tree/test/test_ini_parser.cpp | 12 ++++++++++++
   2 files changed, 14 insertions(+), 1 deletions(-)

Modified: trunk/boost/property_tree/ini_parser.hpp
==============================================================================
--- trunk/boost/property_tree/ini_parser.hpp (original)
+++ trunk/boost/property_tree/ini_parser.hpp 2011-03-28 09:44:16 EDT (Mon, 28 Mar 2011)
@@ -69,6 +69,7 @@
         typedef typename Ptree::key_type::value_type Ch;
         typedef std::basic_string<Ch> Str;
         const Ch semicolon = stream.widen(';');
+ const Ch hash = stream.widen('#');
         const Ch lbracket = stream.widen('[');
         const Ch rbracket = stream.widen(']');
 
@@ -93,7 +94,7 @@
             if (!line.empty())
             {
                 // Comment, section or key?
- if (line[0] == semicolon)
+ if (line[0] == semicolon || line[0] == hash)
                 {
                     // Ignore comments
                 }

Modified: trunk/libs/property_tree/test/test_ini_parser.cpp
==============================================================================
--- trunk/libs/property_tree/test/test_ini_parser.cpp (original)
+++ trunk/libs/property_tree/test/test_ini_parser.cpp 2011-03-28 09:44:16 EDT (Mon, 28 Mar 2011)
@@ -47,6 +47,12 @@
     "Key1=Data1\n" // No section
     "Key2=Data2\n";
 
+// Treat # as comment.
+const char *ok_data_6 =
+ "# Comment\n"
+ "[Section1]\n"
+ "Key1=Data1\n";
+
 // Erroneous data
 const char *error_data_1 =
     "[Section1]\n"
@@ -132,6 +138,12 @@
         "testok5.ini", NULL, "testok5out.ini", 3, 10, 8
     );
 
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_6, NULL,
+ "testok6.ini", NULL, "testok6out.ini", 3, 5, 12
+ );
+
     generic_parser_test_error<Ptree, ReadFunc, WriteFunc, ini_parser_error>
     (
         ReadFunc(), WriteFunc(), error_data_1, NULL,


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk