Sloppy's Blog

Hello Toml

一般的配置文件都是json,xml,YAML,etc.今天刚好又看见一个极简的TOML,顺道就写了一个简单的测试程序,做下标记

基于CPP,添加开TinyToml的头文件,这个是一个Head Only的Lib,下载地址为:https://github.com/coolexp/tinytoml
新建一个文件,Config.toml,内容如下:

    s1 = "HelloToml" # test data

测试代码:

    #include头文件
    std::string v=FileUtils::getInstance()->getStringFromFile("Config.toml");#cocos2d-x的文件帮助类,用ifstream也可以。
    std::stringstream ss(v);
    toml::internal::Parser p(ss);
    const toml::Value& vp = p.parse();
    const toml::Value* x = vp.find("s1");
    if (x && x->is()) {
        std::string valueStr = x->as();
    }

参考链接:
https://github.com/toml-lang/toml
https://github.com/mayah/tinytoml