www.digitalmars.com         C & C++   DMDScript  

D - INI files

reply "Vathix" <vathix dprogramming.com> writes:
I just made a portable module for reading and writing INI files. INI files
come in handy! This code is public domain. Here's a little example:

Ini ini = new Ini("foo.ini");
with(ini.addSection("mysection"))
{
    value("keyname", "hello world");
}
ini.save();
Nov 30 2003
next sibling parent "Walter" <walter digitalmars.com> writes:
Unit tests too! I like it.

"Vathix" <vathix dprogramming.com> wrote in message
news:bqdfpi$125h$1 digitaldaemon.com...
 I just made a portable module for reading and writing INI files. INI files
 come in handy! This code is public domain. Here's a little example:

 Ini ini = new Ini("foo.ini");
 with(ini.addSection("mysection"))
 {
     value("keyname", "hello world");
 }
 ini.save();

Dec 01 2003
prev sibling next sibling parent "C. Sauls" <ibisbasenji yahoo.com> writes:
Vathix wrote:
 I just made a portable module for reading and writing INI files. INI files
 come in handy! This code is public domain. Here's a little example:
 
 Ini ini = new Ini("foo.ini");
 with(ini.addSection("mysection"))
 {
     value("keyname", "hello world");
 }
 ini.save();
 

I'd thought of doing my own INI lib, now I guess I won't have to. I like your concept of wrapping sections into objects, very slick. C. Sauls Invironz
Dec 02 2003
prev sibling parent reply Chris Sauls <ibisbasenji yahoo.com> writes:
I still love it, just wanted to throw in a few suggestions.  First off, 
do you think IniSection.keys() might be rewritable to the following?:

IniKey[] keys()
{
	IniKey[] ikeys;
	foreach(IniKey ikey; this)
	{
		ikeys ~= ikey;
	}
	return ikeys;
}

I tried to preserve your coding style, but I think its a bit cleaner. 
Correct or ignore me if I missed an important reason for it being the 
way it already is.

Also, could we get IniSection.value(IniKey, char[]) and 
IniSection.value(char[], char[]) to return the new value back to the 
calling expression?  Makes for a more transparent interface in my 
opinion, but I'm odd.

C. Sauls
Invironz
Dec 04 2003
parent "Vathix" <vathix dprogramming.com> writes:
"Chris Sauls" <ibisbasenji yahoo.com> wrote in message
news:bqnis4$m4p$1 digitaldaemon.com...
 I still love it, just wanted to throw in a few suggestions.  First off,
 do you think IniSection.keys() might be rewritable to the following?:

 IniKey[] keys()
 {
 IniKey[] ikeys;
 foreach(IniKey ikey; this)
 {
 ikeys ~= ikey;
 }
 return ikeys;
 }

 I tried to preserve your coding style, but I think its a bit cleaner.
 Correct or ignore me if I missed an important reason for it being the
 way it already is.

The way I have it, ikeys doesn't need to be reallocated at all. It might waste a few bytes, but I don't think it's enough to worry about.
 Also, could we get IniSection.value(IniKey, char[]) and
 IniSection.value(char[], char[]) to return the new value back to the
 calling expression?  Makes for a more transparent interface in my
 opinion, but I'm odd.

The way I see it is that you already have the value, why have the function do a bit more work when it doesn't need to :) - I know I'm way over concerned with efficiency.
Dec 04 2003