我希望能够解析一个数字,以存储其原始来源并跟踪其在源中的位置,并将其保留在结构本身中.
这是我到目前为止:
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/home/support/iterators/line_pos_iterator.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
#include <iostream>
#include <iomanip>
#include <ios>
#include <string>
#include <complex>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
struct Position
{
Position()
: line(-1)
{
}
size_t line;
};
struct Number : public Position
{
Number()
: Position()
, value(-1)
, source()
{
}
unsigned value;
std::string source;
};
using namespace boost::spirit;
BOOST_FUSION_ADAPT_STRUCT(Number,
(unsigned, value)
(std::string, source)
(size_t, line)
);
template <typename Iterator>
struct source_hex : …Run Code Online (Sandbox Code Playgroud) 寻找能够返回INI文件的行号的一些C++库(如boost :: program_options),其中找到了给定的选项或部分.
用例:
我要求该库在"[SSS]"部分中找到值"vvv".库返回行号,其中找到"[SSS]"部分中的"vvv",或-1.它让我有能力说"第55行:vvv必须<256".
我迭代INI文件的部分并验证他们的名字.当发现一些狂野的部分时,我说:"第55行:[哈哈哈]部分未知".
更新:我知道"INI比猛犸象大",但目前我必须将大型Windows项目移植到跨平台,并且不能很快摆脱.ini文件.