This module contains functions for writing config files or converting config tables to string representations that are human-readable, loadable or both.
Procs
proc dump(table: ConfigTable): string {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Converts a config table into a human-readable format similar to JSON. This should only ever be used for debugging, if you want to convert a config table to a string you can load again then use the toString() procedure.
proc newConfigTable(): ConfigTable {....raises: [], tags: [], forbids: [].}
- Simply returns a new, empty, ConfigTable object.
proc newValue(value: bool): ConfigValue {....raises: [], tags: [], forbids: [].}
proc newValue(value: int): ConfigValue {....raises: [], tags: [], forbids: [].}
proc newValue(value: seq[ConfigValue]): ConfigValue {....raises: [], tags: [], forbids: [].}
proc newValue(value: string): ConfigValue {....raises: [], tags: [], forbids: [].}
proc newValue(value: varargs[ConfigValue]): ConfigValue {....raises: [], tags: [], forbids: [].}
proc setKey(table: var ConfigTable; section, key: string; value: ConfigValue) {. ...raises: [], tags: [], forbids: [].}
-
Changes a key of a section inside of a table to a specific value
Example: cmd: --run:off
import iniplus var table = newConfigTable() # Creates a String ConfigValue object valueStr = newValue("Hello World!") # Creates a Sequence ConfigValue object valueArr = newValue( newValue("Hello World!"), newValue(1000) ) # Inserting a handmade string into a table table.setKey("handmade","quote",valueStr) assert table.getString("handmade","quote") == "Hello World!" # Inserting a handmade array into a table table.setKey("handmade","list",valueArr) assert table.getArray("handmade", "list")[0].stringVal == "Hello World!" assert table.getArray("handmade", "list")[1].intVal == 1000
proc setKeyMultiVal(table: var ConfigTable; section, key: string; value: string) {. ...raises: [ValueError], tags: [], forbids: [].}
-
Sets a value in a table to a multi value (array)
Example: cmd: --run:off
import iniplus var table = newConfigTable() table.setKeyMultiVal("multi","list","[\"Hello World!\",1000]") assert table.getArray("multi","list")[0].stringVal == "Hello World!" assert table.getArray("multi","list")[1].intVal == 1000
proc setKeySingleVal(table: var ConfigTable; section, key: string; value: string) {. ...raises: [ValueError], tags: [], forbids: [].}
-
Sets a value in a table to a single value (string, bool or int)
Example: cmd: --run:off
import iniplus var table = newConfigTable() table.setKeySingleVal("single","number","1000") table.setKeySingleVal("single","quote","\"Hello World!\"") table.setKeySingleVal("single","true_false","false") assert table.getString("single","quote") == "Hello World!" assert table.getInt("single","number") == 1000 assert table.getBool("single", "true_false") == false
proc toString(table: ConfigTable): string {....raises: [ValueError, KeyError], tags: [], forbids: [].}
- Converts a configuration table into a loadable, human-readable string.
proc toString(val: ConfigValue): string {....raises: [], tags: [], forbids: [].}
- Converts a configuration value into a loadable, human-readable string.
proc writeToFile(filename: string; table: ConfigTable): bool {....raises: [], tags: [WriteIOEffect], forbids: [].}