www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Best way to handle settings files (ini file syntax or similar)

reply Samuel Lampa <samuel.lampa gmail.com> writes:
Hi,

I was wondering what would be the most straightforward way to handle 
settings files in D, currently?

Is there support for ini filesor something similar, or would I be better 
off going with JSON or XML or similar?

BR
// Samuel
Feb 27 2013
parent reply "Dicebot" <m.strashun gmail.com> writes:
I use this simple snippet to get quick and dirty key-value config:

---
string[string] data;
foreach( line; readText(filename).splitLines() )
{
     auto config_pair = array(
         filter!("a.length > 0")(
             map!(strip)(
                 line.splitter("=")
             )
         )
     );
     data[config_pair[0]] = config_pair[1];
}
---

For anything even remotely complex I would have probably chosen 
JSON, either new std.json pending for review (not current 
std.json!) or vibe.data.json from vibed.org project.
Feb 27 2013
next sibling parent reply "Dicebot" <m.strashun gmail.com> writes:
Btw now I have actually noticed it is really bad and dirty, so 
good to sometimes check your 2-year code. I think you can write 
better one anyway, just an example of how small it can be.
Feb 27 2013
parent Samuel Lampa <samuel.lampa gmail.com> writes:
On 02/27/2013 10:46 PM, Dicebot wrote:
 Btw now I have actually noticed it is really bad and dirty, so good to 
 sometimes check your 2-year code. I think you can write better one 
 anyway, just an example of how small it can be.
Thanks! Yeah, you're right, rolling an own is not a too big deal. Just wanted to make sure I'm not missing something :) Best Regards // Samuel
Feb 27 2013
prev sibling next sibling parent Lubos Pintes <lubos.pintes gmail.com> writes:
Which JSON is better? I already saw Vibe's JSON, but don't know where is 
that new std.json.
Dňa 27. 2. 2013 22:36 Dicebot  wrote / napísal(a):
 I use this simple snippet to get quick and dirty key-value config:

 ---
 string[string] data;
 foreach( line; readText(filename).splitLines() )
 {
      auto config_pair = array(
          filter!("a.length > 0")(
              map!(strip)(
                  line.splitter("=")
              )
          )
      );
      data[config_pair[0]] = config_pair[1];
 }
 ---

 For anything even remotely complex I would have probably chosen JSON,
 either new std.json pending for review (not current std.json!) or
 vibe.data.json from vibed.org project.
Feb 28 2013
prev sibling parent reply Stephan Schiffels <stschiff0815 googlemail.com> writes:
Am 27.02.13 21:36, schrieb Dicebot:
 For anything even remotely complex I would have probably chosen JSON, 
 either new std.json pending for review (not current std.json!) or 
 vibe.data.json from vibed.org project.
Which std.json are you referring to? There is no std.json2 or something in the review queue.
Feb 28 2013
parent reply "Dicebot" <m.strashun gmail.com> writes:
On Thursday, 28 February 2013 at 17:53:08 UTC, Stephan Schiffels 
wrote:
 Am 27.02.13 21:36, schrieb Dicebot:
 For anything even remotely complex I would have probably 
 chosen JSON, either new std.json pending for review (not 
 current std.json!) or vibe.data.json from vibed.org project.
Which std.json are you referring to? There is no std.json2 or something in the review queue.
Hm, now that I look at wiki, probably false memories. I could have sworn I have tried one intended to be proposed for review about a year ago and can't anything resembling it now when you asked :(
Feb 28 2013
parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Thursday, February 28, 2013 18:57:37 Dicebot wrote:
 On Thursday, 28 February 2013 at 17:53:08 UTC, Stephan Schiffels
 
 wrote:
 Am 27.02.13 21:36, schrieb Dicebot:
 For anything even remotely complex I would have probably
 chosen JSON, either new std.json pending for review (not
 current std.json!) or vibe.data.json from vibed.org project.
Which std.json are you referring to? There is no std.json2 or something in the review queue.
Hm, now that I look at wiki, probably false memories. I could have sworn I have tried one intended to be proposed for review about a year ago and can't anything resembling it now when you asked :(
A while ago Robert Jacques (if I remember who it was correctly) indicated that he had a major rewrite of std.json, but it required an overhaul of std.variant (which he'd also done), so that would have needed to be done first. However, he never got any of it ready for review. IIRC, he felt that needed to polish some stuff up before that, and he doesn't appear to ever have done it. So, I have no idea where that stands now. He's still around and posts at least from time to time, but maybe he just doesn't have time to work on D right now. I don't know. - Jonathan M Davis
Feb 28 2013