【问题标题】:How to support config file syntax “key value” in Boost::Program_Options?如何在 Boost::Program_Options 中支持配置文件语法“键值”?
【发布时间】:2011-08-05 09:39:23
【问题描述】:

默认配置文件语法是“key=value”。如何支持配置文件语法“key value”?

【问题讨论】:

    标签: c++ boost boost-program-options


    【解决方案1】:

    语法由内置的命令行解析器决定。如果需要,您可以提供自己的解析器类。看一下Boost源码中的主要解析函数void common_config_file_iterator::get()。

    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));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 2022-06-30
      相关资源
      最近更新 更多