D - INI files
- Vathix (300/300) Nov 30 2003 I just made a portable module for reading and writing INI files. INI fil...
- Walter (3/11) Dec 01 2003 Unit tests too! I like it.
- C. Sauls (5/15) Dec 02 2003 I'd thought of doing my own INI lib, now I guess I won't have to. I
- Chris Sauls (20/20) Dec 04 2003 I still love it, just wanted to throw in a few suggestions. First off,
- Vathix (7/25) Dec 04 2003 The way I have it, ikeys doesn't need to be reallocated at all. It might
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 M3DD 9FEL97, ;V8 =&AE(&9O<FUA=#H- M9"X-"D-O;6UE;G1S('-T87)T('=I=& .R!A;F0 <VAO=6QD(&)E(&]N('1H 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;&4 <&%T:"P :70G<R!R96QA=&EV92!T;R!T:&4 5VEN9&]W<R!D:7)E8W1O M=R!L;VYG('-E8W1I;VYS+VME>7,O=F%L=65S(&UA>2!B92X-"DEF('1H97)E M(&%R92!D;W5B;&4 <75O=&5S(&%R;W5N9"!A('9A;'5E+"!7:6YD;W=S(')E M;6]V97, =&AE;2X-"D%L;"!K97DO=F%L=64 <&%I<G, ;75S="!B92!I;B!A M<FEV871E(&EM<&]R="!S=&0N9FEL92P <W1D+G-T<FEN9RP <W1D+G-T<F5A M=6YM;V1I9FEE9 T*"2\O:68 ;6]D:69I960L(&1A=&$ :7, <V5T('1O(&YU M:65D(#T M"0EI;G0 <F5S=6QT(#T ,#L-" D)=6EN="!I.PT*"0E);FE+97D :6ME>3L- M" D)9F]R*&D /2 P.R!I("$](&QI;F5S+FQE;F=T:#L M"0EI:V5Y(#T M"0D)>PT*"0D)"7)E<W5L=" ](&1G*&EK97DI.PT*"0D)"6EF*')E<W5L="D- M;FE+97E;;&EN97,N;&5N9W1H73L-" D)=6EN="!I(#T ,#L-" D)9F]R96%C M:"A);FE+97D :6ME>3L =&AI<RD-" D)>PT*"0D):6ME>7-;:2LK72 ](&EK M+V9I;F0 =&AI<R!K97D 86YD(')E='5R;B!I="P-" DO+V]R(')E='5R;G, M;G5L;"!I9B!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 M=&EN9R!K97DG<R!V86QU90T*"79O:60 =F%L=64H26YI2V5Y(&EK97DL(&-H M;#L- M('-E="!I=', =F%L=64-" EV;VED('9A;'5E*&-H87);72!K97E.86UE+"!C 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 M(&1I<F5C=&QY(&=E="!T:&4 =F%L=64-" EC:&%R6UT =F%L=64H8VAA<EM= M(&9O<B!V86QU92AK97E.86UE+"!N97=686QU92D-" DO+W-E=', =&AE('9A M;'5E+"!C<F5A=&EN9R!T:&4 :V5Y(&EF(&YE961E9 T*"79O:60 ;W!);F1E M>"AC:&%R6UT :V5Y3F%M92P 8VAA<EM=(&YE=U9A;'5E*0T*"7L-" D)=F%L M=64H:V5Y3F%M92P ;F5W5F%L=64I.PT*"7T-" D-" D-" DO+W)E;6]V92!T M:6YE<UMI73L-" D)"6EF*&EK97D )B8 (7-T9"YS=')I;F<N:6-M<"AI:V5Y M+E]N86UE+"!K97E.86UE*2D-" D)"7L-" D)"0EI9BAI(#T](&QI;F5S+FQE M;'-E(&EF*&D /3T ,"D-" D)"0D);&EN97, /2!L:6YE<ULQ("XN(&QI;F5S M:5T ?B!L:6YE<UMI("L ,2 N+B!L:6YE<RYL96YG=&A=.PT*"0D)"5]I;FDN M7VUO9&EF:65D(#T M:6QE.PT*"6)I="!?;6]D:69I960 /2!F86QS93L-" E);FE396-T:6]N6UT M"0D)<W1D+G-T<F5A;2YS=&1O=70N<')I;G1F*"))3DD <&%R<VEN9R!F:6QE M26YD97 /2 P.R -" T*"0ET<GD-" D)>PT*"0D)9&%T82 ](&-A<W0H8VAA M96%M+G-T9&]U="YW<FET95-T<FEN9R B24Y)(&YO(&9I;&4 =&\ <&%R<V5< M>PT*"0D)9&5B=6<H24Y)*0T*"0D)"7-T9"YS=')E86TN<W1D;W5T+G=R:71E M96UE;G0 +6DM('!A<W0 96YD('-O('5N9V5T8R!W;W)K<R!P<F]P97)L>0T* M"0D):68H*RMI(#X](&1A=&$N;&5N9W1H*0T*"0D)"7)E='5R;B P.PT*"0D) M;F4 /2!N97< 26YI3&EN93L-" D)"6EL:6YE+F1A=&$ /2!D871A6VQI;F53 M=&%R=$EN9&5X("XN(&E=.PT*"0D)9&5B=6<H24Y)*0T*"0D)"7-T9"YS=')E M86TN<W1D;W5T+G!R:6YT9B B24Y)(&QI;F4Z("<E+BIS)UQN(BP <W1D+G-T M<FEN9RYR97!L86-E*'-T9"YS=')I;F<N<F5P;&%C92AS=&0N<W1R:6YG+G)E M<&QA8V4H:6QI;F4N9&%T82P (EQ<(BP (EQ<7%PB*2P (EQR(BP (EQ<<B(I M+" B7&XB+" B7%QN(BDI.PT*"0D):7-E8RYL:6YE<R!^/2!I;&EN93L-" D) M7'(G. T*"0D)"0EE;VPH*3L-" D)"0D)8V R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M" DO+W=R:71E<R!C;VYT96YT<R!T;R!D:7-K+"!E=F5N(&EF('1H97)E('=E M:69I960 /2!F86QS93L-" T*"0EI9B A:7-E8W,N;&5N9W1H*0T*"0D)<F5T M8W-;,%TN7VYA;64N;&5N9W1H*0T*"0D)9V]T;R!W<FET95]N86UE.PT*"0EE M;'-E("\O9FER<W0 <V5C=&EO;B!D;V5S;B=T(&AA=F4 82!N86UE.R!J=7-T M(&ME>7, 870 <W1A<G0 ;V8 9FEL90T*"0D)9V]T;R!A9G1E<E]N86UE.PT* M"0D)>PT*"0D)"0EI:V5Y(#T 8V%S="A);FE+97DI:7-E8RYL:6YE<UMJ73L- M" D)"0D):68H:6ME>2D-" D)"0D)"6EK97DN9&%T82 ](&EK97DN7VYA;64 M9BYW<FET95-T<FEN9RAI<V5C+FQI;F5S6VI=+F1A=&$I.PT*"0D)"0EF+G=R M" DO+V9I;F1S(&$ <V5C=&EO;CL <F5T=7)N<R!N=6QL(&EF(&ET(&1O97-N M(&$ <V5C=&EO;B!A;F0 <F5T=7)N<R!I="P-" DO+V]R(&-R96%T97, =&AE M('-E8W1I;VX 86YD(')E='5R;G, :70-" E);FE396-T:6]N(&%D9%-E8W1I M:6]N*&YA;64I.PT*"0EI9B A:7-E8RD-" D)>PT*"0D):7-E8R ](&YE=R!) M;FE396-T:6]N*'1H:7,L(&YA;64I.PT*"0D)7VUO9&EF:65D(#T =')U93L- M*3L-" D)"6EF*')E<W5L="D-" D)"0EB<F5A:SL-" D)?0T*"0ER971U<FX M96-S6VE=+E]N86UE*2D-" D)"7L-" D)"0EI9BAI(#T](&ES96-S+FQE;F=T M(&EF*&D /3T ,"D-" D)"0D):7-E8W, /2!I<V5C<ULQ("XN(&ES96-S+FQE M?B!I<V5C<UMI("L ,2 N+B!I<V5C<RYL96YG=&A=.PT*"0D)"5]M;V1I9FEE M(BP (FIK;"(I.PT*"0EV86QU92 B8F%R(BP (G=E92$B*3L-" D)=F%L=64H M="AI;FE;(D9O;R)=6R)Y97,B72 ]/2 B;F\B*3L-" ED96QE=&4 :6YI.PT* M75LB0F%R(ET /3T (G=E92$B*3L-" EA<W-E<G0H:6YI6R)&;V\B75LB>65S M/2 B=')U92(I.PT*"6%S<V5R="AI;FE;(D9/3R)=6R)"87(B72 ]/2 B=V5E M(2(I.PT*"6%S<V5R="AI;FE;(C4U(ET /3T](&YU;&PI.PT*"6%S<V5R="AI M;FE;(FAE;&QO(EU;(EEE<R)=(#T]/2!N=6QL*3L-" 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; 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 ` end
Nov 30 2003
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
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
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
"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