Re: ini library in OSX
as you properly know, ini files don't support sections arrays. If you know all items at compile time, you could create structs for all of them, but that is properly not what you're looking for.
Re: ini library in OSX
On Monday, 22 December 2014 at 11:04:10 UTC, Robert burner Schadek wrote: On Saturday, 20 December 2014 at 08:09:06 UTC, Joel wrote: On Monday, 13 October 2014 at 16:06:42 UTC, Robert burner Schadek wrote: On Saturday, 11 October 2014 at 22:38:20 UTC, Joel wrote: On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote: some self promo: http://code.dlang.org/packages/inifiled I would like an example? go to the link and scroll down a page How do you use it with current ini files ([label] key=name)? I think I don't follow? readINIFile(CONFIG_STRUCT, "filename.ini"); ? I have a ini file that has price goods date etc for each item. I couldn't see how you could have (see below). It's got more than section, I don't know how to do that with your library. In this form: [section0] day=1 month=8 year=2013 item=Fish'n'Chips cost=3 shop=Take aways comment=Don't know the date [section1] day=1 month=8 year=2013 item=almond individually wrapped chocolates (for Cecily), through-ties cost=7 shop=Putaruru - Dairy (near Hotel 79) comment=Don't know the date or time. Also, what is CONFIG_STRUCT? - is that for using 'struct' instead of 'class'?
Re: ini library in OSX
On Saturday, 20 December 2014 at 08:09:06 UTC, Joel wrote: On Monday, 13 October 2014 at 16:06:42 UTC, Robert burner Schadek wrote: On Saturday, 11 October 2014 at 22:38:20 UTC, Joel wrote: On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote: some self promo: http://code.dlang.org/packages/inifiled I would like an example? go to the link and scroll down a page How do you use it with current ini files ([label] key=name)? I think I don't follow? readINIFile(CONFIG_STRUCT, "filename.ini"); ?
Re: ini library in OSX
On Monday, 13 October 2014 at 16:06:42 UTC, Robert burner Schadek wrote: On Saturday, 11 October 2014 at 22:38:20 UTC, Joel wrote: On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote: some self promo: http://code.dlang.org/packages/inifiled I would like an example? go to the link and scroll down a page How do you use it with current ini files ([label] key=name)?
Re: ini library in OSX
On Saturday, 11 October 2014 at 22:38:20 UTC, Joel wrote: On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote: some self promo: http://code.dlang.org/packages/inifiled I would like an example? go to the link and scroll down a page
Re: ini library in OSX
On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote: some self promo: http://code.dlang.org/packages/inifiled I would like an example?
Re: ini library in OSX
Here's a failed attempt of mine - after the line. I would usually have stuff like the following (right next): Ini ini; ini=new Ini( cfg ); ini["section"]["key"] = value; --- import ini; void main() { import std.conv; //load string data; int i; foreach(item; parseINI(File("test.ini"))) { data ~= item.to!string~"\n"; writeln("[*", i++, ' ', text(item), "*]"); } //save //#not working! data ~= "frog=jump"; // add more information data ~= "frog=jump"; auto file = File("test.ini", "w"); file.write(data); i = 0; foreach(item; parseINI(File("test.ini"))) { writeln("[+", i++, ' ', text(item), "+]"); } }
Re: ini library in OSX
How do you use this ini file parser? - http://dpaste.dzfl.pl/1b29ef20 module rangeini; import std.stdio: File, writeln; import std.range; import std.algorithm: canFind; import std.string: strip, splitLines; import std.traits: Unqual; import std.conv: text; struct ConfigItem { string section; string key; string value; } private struct ConfigItems(Range,string kvSeparators=":=",string commentChars=";#") { Unqual!Range _input; string currentSection = "GLOBAL"; this(Unqual!Range r) { _input = r; skipNonKeyValueLines(); } @property bool empty() { return _input.empty; } @property void popFront() { _input.popFront(); skipNonKeyValueLines(); } @property auto front() { auto line = _input.front; foreach(uint i, const c; line) { if (kvSeparators.canFind(c)) { auto key = line[0..i]; auto value = line[i+1..$]; return ConfigItem(currentSection, key.idup, value.idup); } } return ConfigItem(currentSection, line.idup, ""); } private void skipNonKeyValueLines() { while(!_input.empty) { auto line = strip(_input.front); if (line == "" || isComment(line)) { _input.popFront(); continue; } if (line[0] == '[' && line[$-1] == ']') { /* section start */ currentSection = line[1..$-1].idup; _input.popFront(); continue; } break; } } private static bool isComment(in char[] line) pure @safe { assert (line != ""); auto c = line[0]; if (commentChars.canFind(c)) return true; return false; } } auto parseINIlines(Range)(Range r) if (isInputRange!(Unqual!Range)) { return ConfigItems!(Range)(r); } auto parseINI(string data) { return data.splitLines.parseINIlines; } auto parseINI(File fh) { return fh.byLine.parseINIlines; } unittest { auto data = " general section=possible [Simple Values] key=value spaces in keys=allowed spaces in values=allowed as well spaces around the delimiter = obviously you can also use : to delimit keys from values [All Values Are Strings] values like this: 100 or this: 3.14159265359 are they treated as numbers? : no integers, floats and booleans are held as: strings can use the API to get converted values directly: true [Multiline Values] [No Values] key_without_value empty string value here = [You can use comments] # like this ; or this # By default only in an empty line. # Inline comments can be harmful because they prevent users # from using the delimiting characters as parts of values. # That being said, this can be customized. [Sections Can Be Indented] can_values_be_as_well = True does_that_mean_anything_special = False purpose = formatting for readability # Did I mention we can indent comments, too?"; foreach(item; parseINI(data)) { writeln("[*", text(item), "*]"); } } int main() { return 0; }
Re: ini library in OSX
On Tuesday, 9 September 2014 at 08:57:30 UTC, Dejan Lekic wrote: Or this one: http://dpaste.dzfl.pl/1b29ef20# Thanks Dejan Lekic, I'll look them up.
Re: ini library in OSX
Or this one: http://dpaste.dzfl.pl/1b29ef20#
Re: ini library in OSX
On Monday, 8 September 2014 at 06:32:52 UTC, Joel wrote: Is there any ini library that works in OSX? I've tried the ones I found. I think they have the same issue. Joels-MacBook-Pro:ChrisMill joelcnz$ dmd ini -unittest ini.d(330): Error: cannot pass dynamic arrays to extern(C) vararg functions ini.d(387): Error: undefined identifier 'replace', did you mean 'template replace(E, R1, R2)(E[] subject, R1 from, R2 to) if (isDynamicArray!(E[]) && isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2))'? ini.d(495): Error: cannot pass dynamic arrays to extern(C) vararg functions ini.d(571): Error: cannot pass dynamic arrays to extern(C) vararg functions ini.d(571): Error: cannot pass dynamic arrays to extern(C) vararg functions Joels-MacBook-Pro:ChrisMill joelcnz$ You have a pretty functional INI parser here: http://forum.dlang.org/thread/1329910543.20062.9.camel@jonathan
ini library in OSX
Is there any ini library that works in OSX? I've tried the ones I found. I think they have the same issue. Joels-MacBook-Pro:ChrisMill joelcnz$ dmd ini -unittest ini.d(330): Error: cannot pass dynamic arrays to extern(C) vararg functions ini.d(387): Error: undefined identifier 'replace', did you mean 'template replace(E, R1, R2)(E[] subject, R1 from, R2 to) if (isDynamicArray!(E[]) && isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2))'? ini.d(495): Error: cannot pass dynamic arrays to extern(C) vararg functions ini.d(571): Error: cannot pass dynamic arrays to extern(C) vararg functions ini.d(571): Error: cannot pass dynamic arrays to extern(C) vararg functions Joels-MacBook-Pro:ChrisMill joelcnz$