Customisable INI parser library đź‘Ś
D
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
examples
source/dini
.editorconfig
.gitignore
.travis.yml
LICENSE
dub.json
readme.md

readme.md

dini

BuildStatus Version Downloads Maintained

dini is a library written in D Programming Language that allows you to read and write INI configuration files with ease.

Features

  • Easy to use

    Documentation and examples helps you understand library. It's also very nice to use :).

  • Well documented

    The code is well documented. If you find something that isn't, be sure to open issue about it.

  • Variable lookups

    You can "paste" defined variables values in values using %variable%

  • Section inheriting

    Sections can inherit values from other sections

  • Configurable

    Since version 2

    You can define custom quotes, comments and use custom type to store values (reader only).

    Also, if you want to create custom data from INI, you can use INIReader to construct one.

NOTE: Current development version - 2.0.0 is backwards API compatible, if you have any compatibility issues, please report them.

Quick start

Installation

Stable version

{
    ...
    "dependencies": {
        "dini": "~> 1.0.1"
    }
    ...
}

Latest version

{
    ...
    "dependencies": {
        "dini": "~> 2.0.0-rc"
    }
    ...
}

Usage

Let's check how it works in real life. In the examples, we'll use following configuration file:

[def]
name1=value1
name2=value2

[foo : def]
name1=Name1 from foo. Lookup for def.name2: %name2%

Now, lets try to parse it, we can do it with using code similar to:

import std.stdio;
import dini;

void main()
{
    // Parse file
    auto ini = Ini.Parse("path/to/file.conf");
    
    // Print foo.name1 value
    writeln(ini["foo"].getKey("name1"));
}

You can also set INI variables before parsing:

import std.stdio, std.path;
import dini;

void main()
{
    // Create ini struct instance
    Ini ini;
    
    // Set key value
    ini.setKey("currentdir", getcwd());
    
    // Now, you can use currentdir in ini file
    ini.parse();
    
    // Print foo.name1 value
    writeln(ini["foo"].getKey("currentdir"));
}

This allows for using %currentdir% in configuration file now.

Global Inheriting

If you would like to inherit sections that are in another one, you can use . at the beggining to start from global scope:

[a]
[a.b]

[b]
; Note the dot at beggining
[b.c : .a.b]

Global lookups

The same goes for variable lookups:

[a]
[a.b]
var=test

[b]
[b.c]
var=%.a.b.var%