开发者

How to support config file syntax “key value” in Boost::Program_Options?

开发者 https://www.devze.com 2023-03-25 07:24 出处:网络
The default config file syntax is \"key=value\". How can I support config file syntax “key value开发者_开发百科”?The syntax is determined by the built-in command line parser.You can supply your own

The default config file syntax is "key=value". How can I support config file syntax “key value开发者_开发百科”?


The syntax is determined by the built-in command line parser. You can supply your own parser class if you want. Have a look at the main parsing function, void common_config_file_iterator::get() in the Boost source code.

libs/program_options/src/config_file.cpp:94

// Handle section name
if (*s.begin() == '[' && *s.rbegin() == ']') {
    m_prefix = s.substr(1, s.size()-2);
    if (*m_prefix.rbegin() != '.')
        m_prefix += '.';
}
else if ((n = s.find('=')) != string::npos) {

    string name = m_prefix + trim_ws(s.substr(0, n));
    string value = trim_ws(s.substr(n+1));
0

精彩评论

暂无评论...
验证码 换一张
取 消