Construct empty IniLikeFile, i.e. without any groups or values
Read from file.
Read from range of IniLikeLines.
Alias for saving delegate.
Flags to manage .ini like file reading
Create new group using groupName.
Range of groups in order how they were defined in file.
File path where the object was loaded from.
Get group by name.
Tell whether the string is valid key. For IniLikeFile the valid key is any non-empty string. Reimplement this function in the derived class to throw exception from IniLikeGroup when key is invalid.
Remove group by name.
Use delegate to retrieve strings line by line. Those strings can be written to the file or be showed in text area. Note: returned strings don't have trailing newline character.
Save object to the file using .ini-like format.
Save object to string using .ini like format.
1 string contents = 2 `# The first comment 3 [First Entry] 4 # Comment 5 GenericName=File manager 6 GenericName[ru]=Файловый менеджер 7 # Another comment 8 [Another Group] 9 Name=Commander 10 Comment=Manage files 11 # The last comment`; 12 13 auto ilf = new IniLikeFile(iniLikeStringReader(contents), IniLikeFile.ReadOptions.preserveComments, "contents.ini"); 14 assert(ilf.fileName() == "contents.ini"); 15 assert(ilf.group("First Entry")); 16 assert(ilf.group("Another Group")); 17 assert(ilf.saveToString() == contents); 18 19 auto firstEntry = ilf.group("First Entry"); 20 21 assert(firstEntry["GenericName"] == "File manager"); 22 assert(firstEntry.value("GenericName") == "File manager"); 23 firstEntry["GenericName"] = "Manager of files"; 24 assert(firstEntry["GenericName"] == "Manager of files"); 25 firstEntry["Authors"] = "Unknown"; 26 assert(firstEntry["Authors"] == "Unknown"); 27 28 assert(firstEntry.localizedValue("GenericName", "ru") == "Файловый менеджер"); 29 firstEntry.setLocalizedValue("GenericName", "ru", "Менеджер файлов"); 30 assert(firstEntry.localizedValue("GenericName", "ru") == "Менеджер файлов"); 31 firstEntry.setLocalizedValue("Authors", "ru", "Неизвестны"); 32 assert(firstEntry.localizedValue("Authors", "ru") == "Неизвестны"); 33 34 firstEntry.removeEntry("GenericName"); 35 assert(!firstEntry.contains("GenericName")); 36 firstEntry["GenericName"] = "File Manager"; 37 assert(firstEntry["GenericName"] == "File Manager"); 38 39 assert(ilf.group("Another Group")["Name"] == "Commander"); 40 assert(equal(ilf.group("Another Group").byKeyValue(), [ KeyValueTuple("Name", "Commander"), KeyValueTuple("Comment", "Manage files") ])); 41 42 assert(equal(ilf.byGroup().map!(g => g.name), ["First Entry", "Another Group"])); 43 44 ilf.removeGroup("Another Group"); 45 assert(!ilf.group("Another Group")); 46 assert(equal(ilf.byGroup().map!(g => g.name), ["First Entry"])); 47 48 ilf.addGroup("Another Group"); 49 assert(ilf.group("Another Group")); 50 assert(ilf.group("Another Group").byIniLine().empty); 51 assert(ilf.group("Another Group").byKeyValue().empty); 52 53 ilf.addGroup("Other Group"); 54 assert(equal(ilf.byGroup().map!(g => g.name), ["First Entry", "Another Group", "Other Group"])); 55 56 const IniLikeFile cilf = ilf; 57 static assert(is(typeof(cilf.byGroup()))); 58 static assert(is(typeof(cilf.group("First Entry").byKeyValue()))); 59 static assert(is(typeof(cilf.group("First Entry").byIniLine()))); 60 61 contents = 62 `[First] 63 Key=Value 64 [Second] 65 Key=Value`; 66 ilf = new IniLikeFile(iniLikeStringReader(contents), IniLikeFile.ReadOptions.firstGroupOnly); 67 assert(ilf.group("First") !is null); 68 assert(ilf.group("Second") is null); 69 assert(ilf.group("First")["Key"] == "Value"); 70 71 contents = 72 `[Group] 73 GenericName=File manager 74 [Group] 75 Name=Commander`; 76 77 assertThrown(new IniLikeFile(iniLikeStringReader(contents))); 78 assertNotThrown(new IniLikeFile(iniLikeStringReader(contents), IniLikeFile.ReadOptions.ignoreGroupDuplicates)); 79 80 contents = 81 `[Group] 82 =File manager`; 83 84 assertThrown(new IniLikeFile(iniLikeStringReader(contents))); 85 assertNotThrown(new IniLikeFile(iniLikeStringReader(contents), IniLikeFile.ReadOptions.ignoreInvalidKeys));
Ini-like file.