[RFC] Ini parser

Robik szadows at gmail.com
Fri Feb 17 06:51:32 PST 2012


On Friday, 17 February 2012 at 07:27:52 UTC, Jacob Carlborg wrote:
> On 2012-02-16 21:50, Robik 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

Thanks, it's awesome idea. Added.
>> [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);
>> }
>
> Why the need for ".value"? It would guess because opIndex 
> returns IniKey which both contains the key and the value. I 
> would sugest you add a "alias this" pointing to "value". 
> Something like this.
>
> struct IniKey
> {
>     string name;
>     string value;
>
>     alias value this;
> }




More information about the Digitalmars-d mailing list