https://github.com/rtbo/libconfig-d
Port of libconfig to the D programming language
https://github.com/rtbo/libconfig-d
Last synced: 28 days ago
JSON representation
Port of libconfig to the D programming language
- Host: GitHub
- URL: https://github.com/rtbo/libconfig-d
- Owner: rtbo
- License: bsd-3-clause
- Created: 2016-09-27T05:49:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-16T16:40:16.000Z (over 9 years ago)
- Last Synced: 2025-01-30T19:27:00.268Z (about 1 year ago)
- Language: D
- Size: 61.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome - rtbo/libconfig-d - Port of libconfig to the D programming language (<a name="D"></a>D)
README
# libconfig-d
Port of [libconfig](http://www.hyperrealm.com/libconfig/) to the D programming language.
example:
```d
import config;
import std.stdio;
int main()
{
// read a configuration string (can also read from open file or filename)
auto conf = Config.readString(
`inventory = { books = (
{
title = "Treasure Island";
author = "Robert Louis Stevenson";
price = 29.99;
qty = 5;
}, {
title = "Snow Crash";
author = "Neal Stephenson";
price = 9.99;
qty = 8;
}
)}`
);
// fetch and read nodes
auto books = conf.lookUp("inventory.books").asList;
writeln("Available books in inventory:");
writefln("%-30s %-30s %-6s %s", "TITLE", "AUTHOR", "PRICE", "QTY");
foreach (book; books.children)
{
auto title = book.lookUpValue!string("title");
auto author = book.lookUpValue!string("author");
auto price = book.lookUpValue!float("price");
auto qty = book.lookUpValue!int("qty");
if (!title.isNull && !author.isNull && !price.isNull && !qty.isNull)
{
writefln("%-30s %-30s $%6.2f %3d", title, author, price, qty);
}
}
writeln();
// add nodes and values
auto book = books.add!(Type.Group);
book.addScalar("title", "The Plague");
book.addScalar("author", "Albert Camus");
book.addScalar("price", 8.99);
book.addScalar("qty", 3);
// write to a file (can also write to string)
conf.writeTo(File("updated.cfg", "w").lockingTextWriter());
return 0;
}
```