digitalmars.D.learn - ini library in OSX
- Joel (16/16) Sep 07 2014 Is there any ini library that works in OSX?
- Dejan Lekic (3/19) Sep 09 2014 You have a pretty functional INI parser here:
- Dejan Lekic (1/1) Sep 09 2014 Or this one: http://dpaste.dzfl.pl/1b29ef20#
- Robert burner Schadek (2/2) Sep 11 2014 some self promo:
- Joel (3/5) Oct 11 2014 I would like an example?
- Robert burner Schadek (2/8) Oct 13 2014 go to the link and scroll down a page
- Joel (3/12) Dec 20 2014 How do you use it with current ini files ([label] key=name)?
- Robert burner Schadek (3/16) Dec 22 2014 I think I don't follow?
- Joel (25/42) Dec 22 2014 I have a ini file that has price goods date etc for each item. I
- Robert burner Schadek (3/3) Dec 23 2014 as you properly know, ini files don't support sections arrays.
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$
Sep 07 2014
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
Sep 09 2014
On Tuesday, 9 September 2014 at 08:57:30 UTC, Dejan Lekic wrote:Thanks Dejan Lekic, I'll look them up.
Sep 09 2014
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 { 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: 1000000 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] ; or this [Sections Can Be Indented] can_values_be_as_well = True does_that_mean_anything_special = False purpose = formatting for readability foreach(item; parseINI(data)) { writeln("[*", text(item), "*]"); } } int main() { return 0; }
Sep 09 2014
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), "+]"); } }
Sep 09 2014
some self promo: http://code.dlang.org/packages/inifiled
Sep 11 2014
On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote:some self promo: http://code.dlang.org/packages/inifiledI would like an example?
Oct 11 2014
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:go to the link and scroll down a pagesome self promo: http://code.dlang.org/packages/inifiledI would like an example?
Oct 13 2014
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:How do you use it with current ini files ([label] key=name)?On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote:go to the link and scroll down a pagesome self promo: http://code.dlang.org/packages/inifiledI would like an example?
Dec 20 2014
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:I think I don't follow? readINIFile(CONFIG_STRUCT, "filename.ini"); ?On Saturday, 11 October 2014 at 22:38:20 UTC, Joel wrote:How do you use it with current ini files ([label] key=name)?On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote:go to the link and scroll down a pagesome self promo: http://code.dlang.org/packages/inifiledI would like an example?
Dec 22 2014
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: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'?On Monday, 13 October 2014 at 16:06:42 UTC, Robert burner Schadek wrote:I think I don't follow? readINIFile(CONFIG_STRUCT, "filename.ini"); ?On Saturday, 11 October 2014 at 22:38:20 UTC, Joel wrote:How do you use it with current ini files ([label] key=name)?On Thursday, 11 September 2014 at 10:49:48 UTC, Robert burner Schadek wrote:go to the link and scroll down a pagesome self promo: http://code.dlang.org/packages/inifiledI would like an example?
Dec 22 2014
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.
Dec 23 2014