d-properties 1.0.5

D-language parser and serializer for Java-style properties files.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

d-properties

D-language parser and serializer for Java-style properties files, which conforms to the format specification on Wikipedia.

View this library on code.dlang.org's package listing.

Usage

Add this library to your project with dub add d-properties.

import std.stdio;
import d_properties;

Properties props;

// Read properties from a file:
props = Properties("config.properties");
// Read from multiple files (values in subsequent files overwrite earlier ones):
props = Properties("base_config.properties", "extra.properties");
// Add properties from any additional file (or files):
props.addAll("another_file.properties");
props.addAll("yet_another.properties", "auxiliary.properties");
// Add properties from another Properties object:
Properties other = Properties(["key": "value"]);
props.addAll(other);

// Do stuff with the properties:
writeln(props); // Properties is a struct, so it can be converted to a string.
writeln(props["key"]); // Access property values via [].
props["key"] = "new value"; // Set a property like so.
writeln(props.get("unknown_key", "none")); // Get a property, or fallback to a default.

// Use the in operator to check if properties exist:
if ("unknown_key" in props) writeln("Property is present.");
if ("other_key" !in props) writeln("Property is not present.");

try {// Accessing missing properties with [] will throw MissingPropertyException
    writeln(props["unknown_key"]);
} catch (MissingPropertyException e) {
    writeln("Missing property!");
}

// Save to a file:
props.writeToFile("my_props.properties");
// Add a comment to the top of the file:
props.writeToFile("out.properties", "This is a comment");
// Use a different separator between keys and values (default is " = "):
props.writeToFile("out.properties", null, SeparatorStyle.COLON);
Authors:
Dependencies:
none
Versions:
1.0.5 2023-Aug-24
1.0.4 2022-Mar-30
1.0.3 2022-Mar-29
1.0.2 2022-Jan-10
1.0.1 2021-Nov-12
Show all 7 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 40 downloads total

Score:
0.7
Short URL:
d-properties.dub.pm