std.config
Names with their values, name=value: in memory, and in a file of lines that a person reads and writes, as the settings of a program.
import std.config
config.Config settings = config.load("app.conf") // port=8080, a line for each name
i64 port = settings.getInt("port", 80) // 80 when the file does not say it
string host = settings.getOr("host", "localhost")
settings.setBool("verbose", true)
settings.save("app.conf") // the comments of the file are still thereThe guide: Files, processes and time.
Made from the documentation in the sources of the library.
#Types
#Config
struct ConfigNames with their values, in the order in which they were written. One declared without a value is empty. It is a value: a copy has the names that the first had.
#Config.set
void set(string name, string value)Gives name the text value, in place of the one it had, or as a new line at the end. The spaces around the two are left out. Throws an Error for a name that is empty, has a = or an end of line, or starts with # or ;, and for a value with an end of line: a file could not hold them.
#Config.setInt
void setInt(string name, i64 value)Gives name a whole number.
#Config.setFloat
void setFloat(string name, f64 value)Gives name a number with a fraction.
#Config.setBool
void setBool(string name, bool value)Gives name "true" or "false".
#Config.setLine
void setLine(string line)Reads a line name=value, as those of a file, or of the arguments of a program: the name is what comes before the first =. Throws an Error for a line without a =.
#Config.has
bool has(string name) constWhether name has a value, also an empty one.
#Config.get
string get(string name) constThe value of name, or "" when it has none.
#Config.getOr
string getOr(string name, string otherwise) constThe value of name, or otherwise when it has none.
#Config.getInt
i64 getInt(string name, i64 otherwise) constThe value of name as a whole number, or otherwise when it has none or it is not a number.
#Config.getFloat
f64 getFloat(string name, f64 otherwise) constThe value of name as a number with a fraction, or otherwise when it has none or it is not a number.
#Config.getBool
bool getBool(string name, bool otherwise) constThe value of name as a yes or a no: true for "true", "yes", "on" and "1", false for "false", "no", "off" and "0", in upper or lower case; otherwise when it has none or it is another text.
#Config.remove
bool remove(string name)Takes name and its value away. Returns whether it was there.
#Config.names
list<string> names() constThe names, in the order in which they were written.
#Config.len
i64 len() constHow many names there are.
#Config.clear
void clear()Takes everything away, the comments too.
#Config.text
string text() constThe lines of a file: name=value for each name, in their order, with the comments and the blank lines that parse or load read, each line ended by "\n".
#Config.save
void save(string path) constWrites text() to the file at path, in place of what it had. Throws as fs.writeText when the file cannot be written.
#Functions
#parse
Config parse(string text)The names and the values written in text, a line name=value for each; the blank lines and those that start with # or ; are comments, kept for text() and save. A name written twice has its last value. Throws an Error with the number of the line for one that is not a comment and has no =.
#load
Config load(string path)The names and the values of the file at path, as parse reads them. Throws as fs.readText when the file cannot be read.