ddn.config.ini

INI Configuration Support

This module provides a robust and flexible implementation of INI file parser and writer. It is designed to work seamlessly with ddn.var.

Section_Names: Section names in INI files should follow these guidelines:

  • Alphanumeric characters (a-z, A-Z, 0-9) are always safe
  • Underscores (_), hyphens (-), and periods (.) are commonly supported
  • Spaces and special characters may work but are not recommended for portability
  • Section names are case-sensitive in this implementation
  • Empty section names are not allowed
  • The special section name "global" is reserved when allowGlobalProperties is true

Error_Handling: The toIni(var, string) function may throw:

  • std.stdio.StdioException - If the file cannot be opened or written
  • std.exception.ErrnoException - For other I/O errors

Use the toIni(var) overload returning a string to avoid I/O exceptions.

Types 3

structIniPolicy

Policy for parsing and writing INI files.

Fields
string commentCharsCharacters that start a comment line. Common choices are `;` and `#`.
bool allowGlobalPropertiesAllow properties before the first section. If true, these properties are stored in the root object.
bool strictIf true, the parser will throw an Exception on malformed lines. Malformed lines are those that are not comments, sections, or key-value pairs. If false, such lines are ignored.
structIni

Wrapper for INI configuration data.

Provides convenience methods for working with INI structures stored in a var.

Fields
var dataThe underlying configuration data.
Methods
string[] sections() @propertyReturns an array of section names.
Constructors
this(var data)Constructs an `Ini` object from a `var`.
classIniParseException : Exception

Thrown when INI content cannot be parsed.

Lets callers catch parse errors specifically (analogous to SemVerParseException / AdamException hierarchies elsewhere in ddn).

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__)

Functions 7

private fnstring unescapeIniString(string val)Decode the backslash escapes produced by escapeIniString.
private fnstring escapeIniString(string val)Escape a string for use inside a quoted INI value: control characters become backslash escapes, and `\` and `"` are escaped.
fnIni parseIni(string text, IniPolicy policy = IniPolicy.init)Parses INI content into an `Ini` object.
fnvoid toIni(var v, string filename, IniPolicy policy = IniPolicy.init)Serializes a `var` object to INI format and writes to a file.
private fnvoid validateName(string what, string name, IniPolicy policy)Saves a `var` object to INI format into an output range.
fnvoid save(OutputRange)(var v, auto ref OutputRange sink, IniPolicy policy = IniPolicy.init) if (isOutputRange!(OutputRange, string))
fnstring toIni(var v, IniPolicy policy = IniPolicy.init)Serializes a `var` object to INI format.