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();




begin 666 ini.d
M+R\ 5W)I='1E;B!B>2!#:')I<W1O<&AE<B!%+B!-:6QL97(-"B\O('=W=RYD
M<')O9W)A;6UI;F<N8V]M#0HO+R!4:&ES(&ES(&9R964 8V]D90T*#0H-"B\J
M#0H-"E!O<G1A8FQE(&UO9'5L92!F;W( <F5A9&EN9R!A;F0 =W)I=&EN9R!)
M3DD 9FEL97, ;V8 =&AE(&9O<FUA=#H-" T*6W-E8W1I;VY=#0IK97D]=F%L
M=64-"BXN+ T*#0I,96%D:6YG('-P86-E<R!A;F0 =&%B<R!A<F4 :6=N;W)E
M9"X-"D-O;6UE;G1S('-T87)T('=I=&  .R!A;F0 <VAO=6QD(&)E(&]N('1H
M96ER(&]W;B!L:6YE+ T*#0I)9B!T:&5R92!A<F4 8V]M;65N=',L('-P86-E
M<R!O<B!K97ES(&%B;W9E('1H92!F:7)S="!S96-T:6]N+"!A(&YA;65L97-S
M('-E8W1I;VX :7, 8W)E871E9"!F;W( =&AE;2X-"E1H:7, ;65A;G, =&AE
M<F4 ;F5E9"!N;W0 8F4 86YY('-E8W1I;VYS(&EN('1H92!F:6QE('1O(&AA
M=F4 :V5Y<RX-" T*1&EF9F5R96YC97, =VET:"!7:6YD;W=S)R!P<F]F:6QE
M("A)3DDI(&9U;F-T:6]N<SH-"E=I;F1O=W, .7  9&]E<R!N;W0 86QL;W< 
M=&%B<R!I;B!T:&4 =F%L=64N#0I3;VUE('9E<G-I;VYS(&1O(&YO="!A;&QO
M=R!T:&4 9FEL92!T;R!E>&-E960 -C0 2T(N#0I)9B!N;W0 82!F=6QL(&9I
M;&4 <&%T:"P :70G<R!R96QA=&EV92!T;R!T:&4 5VEN9&]W<R!D:7)E8W1O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!T:&4 :V5Y(&1O97-N)W0 97AI<W0-" E);FE+97D :V5Y*&-H
M87);72!K97E.86UE*0T*"7L-" D)9F]R96%C:"A);FE+97D :6ME>3L =&AI
M<RD-" D)>PT*"0D):68H(7-T9"YS=')I;F<N:6-M<"AI:V5Y+E]N86UE+"!K
M97E.86UE*2D-" D)"0ER971U<FX :6ME>3L-" D)?0T*"0ER971U<FX ;G5L
M;#L +R]D:61N)W0 9FEN9"!I= T*"7T-" T*#0H)+R]S970 =&AI<R!E>&ES
M=&EN9R!K97DG<R!V86QU90T*"79O:60 =F%L=64H26YI2V5Y(&EK97DL(&-H
M87);72!N97=686QU92D-" E[#0H)"6EK97DN7W9A;'5E(#T ;F5W5F%L=64[
M#0H)"5]I;FDN7VUO9&EF:65D(#T =')U93L-" D):6ME>2YD871A(#T ;G5L
M;#L-" E]#0H-" T*"2\O9FEN9"!T:&ES(&ME>2!O<B!C<F5A=&4 :70 86YD
M('-E="!I=', =F%L=64-" EV;VED('9A;'5E*&-H87);72!K97E.86UE+"!C
M:&%R6UT ;F5W5F%L=64I#0H)>PT*"0E);FE+97D :6ME>2 ](&ME>2AK97E.
M86UE*3L-" D):68H(6EK97DI#0H)"7L-" D)"6EK97D /2!N97< 26YI2V5Y
M*&ME>4YA;64I.PT*"0D);&EN97, ?CT :6ME>3L-" D)"2\O7VEN:2Y?;6]D
M:69I960 /2!T<G5E.R O+VYE>'0 8V%L;"!D;V5S('1H:7,-" D)?0T*"0EV
M86QU92AI:V5Y+"!N97=686QU92D[#0H)?0T*#0H-" DO+W-H;W)T8W5T('1O
M(&1I<F5C=&QY(&=E="!T:&4 =F%L=64-" EC:&%R6UT =F%L=64H8VAA<EM=
M(&ME>4YA;64I#0H)>PT*"0EF;W)E86-H*$EN:4ME>2!I:V5Y.R!T:&ES*0T*
M"0E[#0H)"0EI9B A<W1D+G-T<FEN9RYI8VUP*&EK97DN7VYA;64L(&ME>4YA
M;64I*0T*"0D)"7)E='5R;B!I:V5Y+G9A;'5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L-" D-" EI;FDN;W!E;BAI
M;FEF:6QE*3L-" EI;FE;(F)A<B)=+G)E;6]V92 B;F]T=&$B*3L-" EI;FE;
M(F9O;R)=+G)E;6]V92 B8F%R(BD[#0H):6YI+G)E;6]V92 B8F%R(BD[#0H)
M87-S97)T*&EN:5LB8F%R(ET /3T](&YU;&PI.PT*"6%S<V5R="AI;FE;(F9O
M;R)=("$]/2!N=6QL*3L-" EA<W-E<G0H:6YI6R)F;V\B75LB8F%R(ET /3T]
M(&YU;&PI.PT*"6EN:2YR96UO=F4H(F9O;R(I.PT*"6%S<V5R="AI;FE;(F9O
C;R)=(#T]/2!N=6QL*3L-" ED96QE=&4 :6YI.PT*?0T*#0H`
`
end
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