Properties file library for C (or C++)(C(或 C++)的属性文件库)
问题描述
标题一目了然:有谁知道 C 或 C++ 的(好的)属性文件阅读器库吗?
The title is pretty self-explanatory: does anyone know of a (good) properties file reader library for C or, if not, C++?
具体来说,我想要一个处理 Java 中使用的 .properties 文件格式的库:http://en.wikipedia.org/wiki/.properties
To be specific, I want a library which handles the .properties file format used in Java: http://en.wikipedia.org/wiki/.properties
推荐答案
STLSoft 的 1.10 alpha 包含一个 platformstl::properties_file
类.它可用于从文件中读取:
STLSoft's 1.10 alpha contains a platformstl::properties_file
class. It can be used to read from a file:
using platformstl::properties_file;
properties_file properties("stuff.properties");
properties_file::value_type value = properties["name"];
或从记忆中:
properties_file properties(
"name0=value1
name1 value1
name\ 2 : value\ 2 ",
properties_file::contents);
properties_file::value_type value0 = properties["name0"];
properties_file::value_type value1 = properties["name1"];
properties_file::value_type value2 = properties["name 2"];
看起来最新的 1.10 版本有一堆全面的单元测试,并且他们已经升级了类来处理 Java 文档.
Looks like the latest 1.10 release has a bunch of comprehensive unit-tests, and that they've upgraded the class to handle all the rules and examples given in the Java documentation.
唯一明显的问题是 value_type
是 stlsoft::basic_string_view
(在 这篇 Dobb 博士的文章中描述a>),它有点类似于 std::string
,但实际上并不拥有它的内存.据推测,他们这样做是为了避免不必要的分配,大概是出于性能原因,这是 STLSoft 设计所珍视的.但这意味着你不能只写
The only apparent rub is that the value_type
is an instance of stlsoft::basic_string_view
(described in this Dr Dobb's article), which is somewhat similar to std::string
, but doesn't actually own its memory. Presumably they do this to avoid unneccessary allocations, presumably for performance reasons, which is something the STLSoft design holds dear. But it means that you can't just write
std::string value0 = properties["name0"];
但是,您可以这样做:
std::string value0 = properties["name0"].c_str();
还有这个:
std::cout << properties["name0"];
我不确定我是否同意这个设计决定,因为从文件或内存中读取属性的可能性有多大,需要绝对的最后一个周期.我认为他们应该将其更改为默认使用 std::string
,然后在明确需要时使用字符串视图".
I'm not sure I agree with this design decision, since how likely is it that reading properties - from file or from memory - is going to need the absolute last cycle. I think they should change it to use std::string
by default, and then use the "string view" if explicitly required.
除此之外,properties_file
类看起来可以解决问题.
Other than that, the properties_file
class looks like it does the trick.
这篇关于C(或 C++)的属性文件库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C(或 C++)的属性文件库


基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01