Search code examples
configd

dini: how to return key, but not key value?


I need return list of keys, but next code return me only keys values.

string confpath = buildPath(getcwd, "config.ini");
if (!exists(confpath))  throw new Exception("ERROR: config.ini do not exists");
auto config = Ini.Parse(confpath);

foreach (key; config.keys())    
{
    writeln(key);
}

config.ini:

images = C:\images
photos = D:\photos
pictures = E:\stuff\pictures

Expected output:

images
photos
pictures

code output:

C:\images
D:\photos
E:\stuff\pictures

I looked at sources, but do not found where I can return only keys.


Solution

  • If you use my ini wrapper you can return the keys by .keys from IniSection. IMO "dini" is not that good and offers a "non-userfriendly" inifile wrapper. Besides it doesn't follow SafeD which IMO an ini wrapper definitely should as you shouldn't need pointers for parsing a text-format.

    Ex.

    auto keys = ini.getSection("Root").keys;
    

    Or .values for the values.

    You can get it here: https://github.com/BaussProjects/baussini/