ANSI C 中的超便携、小型复杂配置文件库?
我正在寻找一个非常可移植、简约/小型的 ANSI C 语言库,没有外部依赖项(或很少),编译后大小小于 100K。我需要它来创建一个中等复杂的配置文件,并且它必须支持 Unicode。
更多要求:
- 可以使用/嵌入/静态链接到专有代码。在应得的信用处,总会给予信用。
- 不一定是 XML。
- 确实,干净的代码/没有奇怪或不一致的字符串处理。
- UTF-8。
谢谢你们。
I'm looking for a very portable, minimalistic/small XML/configuration language library in ANSI C with no external dependencies (or very few), compiling down to less than 100K. I need it for a moderately complex configuration file, and it must support Unicode.
Some more requirements:
- OK to use/embed/statically link into proprietary code. Credit will always will be given where credit is due.
- Not necessarily XML.
- Really, clean code/no weird or inconsistent string handling.
- UTF-8.
Thank you fellas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在某种程度上类似于这个问题: Is there a good tiny XML parser for an嵌入式 C 项目吗?
我能够调整以下 C 语言 XML 解析器库的编译标志,并在我的 Ubuntu 机器上减少了 50% 以上的大小。 Mini-XML 是唯一接近您要求的:
This is somehow similar to this question: Is there a good tiny XML parser for an embedded C project?
I was able to tweak the compilation flags of the following XML parser libraries for C, and cut down more than 50% of their size on my Ubuntu machine. Mini-XML is the only one close to what you requested:
对于此类用例,IMO Protocol Buffers 是比 XML 更好得多的解决方案。使用协议缓冲区,您可以获得真实的类型和模式,而无需将它们分层在基本 XML 之上。而且语法也更好。
那么用户的实际配置将如下所示:
主协议缓冲区库不符合您的标准,因为它是用 C++ 编写的并且非常大。我正在研究一个更小的实现,称为 upb (即“micro”protobufs) 。它由大约 5k 行 ANSI C 编写而成,编译后的结果为 <50k。
Protocol buffers 有二进制格式和文本格式,它们是等效的。我的库(尚)不支持读取文本格式,但您可以让您的用户使用 Google 标准工具提前将其配置的文本版本转换为二进制格式。然后你的应用程序本身只需要读取二进制格式,并且可以只使用 upb。
upb 刚刚达到了喜欢冒险的用户可以尝试的阶段,但它的边缘仍然有点粗糙,API 仍在发生一些变化。如果您对此感到满意,那么您现在可以尝试深入了解。如果你喜欢更稳定的东西,至少要保持警惕。
IMO Protocol Buffers are a much, much better solution for this kind of use case than XML. With protocol buffers you get real types and a schema without having to layer them on top of base XML. Also the syntax is nicer.
Then the user's actual config would look like this:
The main protocol buffer library does not fit your criteria because it is in C++ and is very large. I am working on a much smaller implementation of the same called upb (ie. "micro" protobufs). It is written in ~5k lines of ANSI C and compiles to <50k.
Protocol buffers have both a binary and a text format, which are equivalent. My library does not (yet) support reading the text format, but you could have your users use the Google standard tool for converting the text version of their config to binary format ahead of time. Then your app itself would only need to read the binary format, and could just use upb.
upb is just now getting to the point where adventurous users could try it out, but it's a bit rough around the edges still and the APIs are still changing somewhat. If you're ok with this, you might try diving in now. If you prefer something more stable, at least keep upb on your radar.