Change the comment character in Boost Program Options?

172 views Asked by At

I have an app that has components in both PHP and C++. They need to share some configuration options, and I'd like to use one file to share these -- a simple config file.

Fortunately, PHP has parse_ini_file() and Boost has Program Options and they share virtually identical semantics. They can both can read all the options I need.

The one "gotcha" here is that PHP's function supports semicolon (";") as the comment character, and Boost supports hash ("#"). PHP used to support hash, but now it throws a deprecated error on it.

I'm pretty sure I can't easily change the comment character in PHP. Anyone know if I can change the Boost comment character? I'd love to not have to rewrite all this functionality just for comments.

1

There are 1 answers

0
CLWill On

Figured out a solution to this problem.

Given that Boost is reasonably robust, I couldn't see a reasonable way to replace the comment character, and the # is a fairly accepted comment character in config files, I solved it in PHP.

I load the config file using file_get_contents, use a preg_replace to remove the lines that begin with #, then pass the result through parse_ini_string.