Feature set to be understood by the parser.
Type of a token (as output by the parser)
Determines whether a type T is a string type compatible with this library.
Convenience function to create a low-level filtered parser
Convenience function to create a low-level parser
Parses an INI string into an associate array.
Parses an INI string into a document ("DOM").
Parses an INI string into a section-less associate array. All sections are merged.
Resolves escape sequences and performs line folding.
Serializes a key + value pair to a string in INI format.
Serializes an IniKeyValuePair to a string in INI format.
Serializes an IniSection to a string in INI format.
Serializes an IniDocument to a string in INI format.
Serializes an AA to a string in INI format.
Serializes a nested AA to a string in INI format.
DOM representation of an INI document
Low-level INI parser with filtered output
Data entry of an INI document
Low-level INI parser
Section of an INI document
Token of INI data (as output by the parser)
Depending on the dialect and string type, IniParser can operate in one of these three modes:
a) If a given dialect requests no mutation of the input data (i.e. no escape sequences, no concaternation of substrings etc.) and is therefore possible to implement with slicing operations only, the parser will be non-destructive and not do any heap allocations. Such a parser is verifiably @nogc, too.
b) In cases where a dialect requires data-mutating operations, there are two ways for a parser to implement them:
b.0) Either perform those mutations on the input data itself and alter the contents of that buffer. Because of the destructive nature of this operation, it can be performed only once safely. (Such an implementation could optionally fix up the modified data to become valid and parsable again. Though doing so would come with a performance overhead.)
b.1) Or allocate a new buffer for the result of the operation. This also has the advantage that it works with immutable and const input data. For convenience reasons the GC is used to perform such allocations.
Use IniParser.isDestructive to check for the operating mode.
The construct a non-destructive parser despite a mutable input data, specify const(char)[] as the value of the string template parameter.
char[] mutableInput = [ /* … */ ]; auto parser = makeIniParser!(dialect, const(char)[])(mutableInput); assert(parser.isDestructive == false);
// INI example data (e.g. from an `autorun.inf` file) static immutable string rawIniData = "[autorun]\n" ~ "open=setup.exe\n" ~ "icon=setup.exe,0\n"; // Parse the document into an associative array: string[string][string] data = parseIniAA(rawIniData); string open = data["autorun"]["open"]; string icon = data["autorun"]["icon"]; assert(open == "setup.exe"); assert(icon == "setup.exe,0");
// INI example data (e.g. from an `autorun.inf` file) static immutable string rawIniData = "[autorun]\n" ~ "open=setup.exe\n" ~ "icon=setup.exe,0\n"; // Parse the document into a flat associative array. // (Sections would get merged, but there is only one section in the // example anyway.) string[string] data = parseIniMergedAA(rawIniData); string open = data["open"]; string icon = data["icon"]; assert(open == "setup.exe"); assert(icon == "setup.exe,0");
// INI example data (e.g. from an `autorun.inf` file): static immutable string rawIniData = "[autorun]\n" ~ "open=setup.exe\n" ~ "icon=setup.exe,0\n"; // Parse the document. IniDocument!string document = parseIniDocument(rawIniData); // Let’s search for the value of an entry `icon` in the `autorun` section. static string searchAutorunIcon(IniDocument!string document) { // Iterate over all sections. foreach (IniSection!string section; document.sections) { // Search for the `[autorun]` section. if (section.name == "autorun") { // Iterate over all items in the section. foreach (IniKeyValuePair!string item; section.items) { // Search for the `icon` entry. if (item.key == "icon") { // Found! return item.value; } } } } // Not found! return null; } // Call our search function. string icon = searchAutorunIcon(document); // Finally, verify the result. assert(icon == "setup.exe,0");
INI configuration file support
This module provides a configurable INI parser with support for multiple “dialects” of the format.
Getting started