[RFC] Ini parser
Manu
turkeyman at gmail.com
Thu Feb 16 14:29:16 PST 2012
I wonder if there is a problem with a 'standard' ini parser, in that ini
files are not really very standard.
I have seen a lot of ini files with scope (also also use this in some of my
own apps), will I be able to parse these with your parser?
[section]
{
key = value
key2 = value
[subsection]
{
subkey = value
}
}
?
I notice your interesting delimiters too, I've never seen anything like
that in an ini file before, where did you see that? What makes it standard?
I might like to use something like that if I had thought it was a normal
thing to use in an ini file...
On 16 February 2012 22:50, Robik <szadows at gmail.com> wrote:
> Greetings.
>
> Recently, I've been working on INI parser in D. The main goals were to
> keep code easy and well documented. Suggestions are really welcome(main
> reason of this thread) because it needs polishing and stuff.
>
> It provides simple interface for operating on parsed file, including
> useful features like section inheriting and variable lookups. Here is
> simple example taken from README with little modifications:
> import std.stdio;
> void main()
> {
> // Hard code the contents
> string c = "
> # defaults
> [def]
> name1:value1
> name2:value2
>
> ; override defaults
> [foo : def]
> name1=Name1 from foo. Lookup for def.name2: %name2%";
>
> // create parser instance
> auto iniParser = new IniParser();
>
> // Set ini structure details; can be ommited
> iniParser.commentChars = [';', '#'];
> iniParser.delimChars = ['=', ':'];
>
>
> // parse
> auto ini = iniParser.parse(c);
>
> // write foo.name1 value
> writeln(ini.getSection("foo")[**"name1"].value);
> }
>
> You can also define parsing details, like commentCharacters* and others.
> As for the keys, structure is used rather than associative arrays. There's
> also bug** that does not allow chaining with opCall which I hope will be
> fixed :).
>
> IniStructure (result of parsing) overloads some basic operators allowing
> you to looping through it and accessing data with opIndex and opCall.
>
> Feel free to share suggestions, changes, help me make it better :).
>
> Repo: https://github.com/robik/DIni
> * https://github.com/robik/DIni/**blob/master/src/dini.d#L400<https://github.com/robik/DIni/blob/master/src/dini.d#L400>
> ** http://d.puremagic.com/issues/**show_bug.cgi?id=7210<http://d.puremagic.com/issues/show_bug.cgi?id=7210>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120217/176864b1/attachment.html>
More information about the Digitalmars-d
mailing list