An alternative parsecfg
configuration parser for Nim.
Aim of this project is the following:
-
Resolve unintended interpretation of configuration files.
parsecfg
sometimes doesn't parse key-value pairs correctly depending on how the key and value are represented in the file.Example:
Key Value PairNamedCounts=(("DiscoveryLobbyMatchmakingPlay", 23),("DiscoveryLobbyMatchmakingPlay_HotfixVer", 0),("lastfrontendflow_Fortnite", 23),("lastfrontendflow_Fortnite_HotfixVer", 0),("UEnableMultiFactorModal::ShouldShowMFASplashScreen", 23),("UEnableMultiFactorModal::ShouldShowMFASplashScreen_HotfixVer", 0),("FrontendContext:ShouldShowSocialImport", 23),("FrontendContext:ShouldShowSocialImport_HotfixVer", 0))
What it is parsed as
namedcounts="""(("DiscoveryLobbyMatchmakingPlay", 23),("DiscoveryLobbyMatchmakingPlay_HotfixVer", 0),("lastfrontendflow_Fortnite", 23),("lastfrontendflow_Fortnite_HotfixVer", 0),("UEnableMultiFactorModal::ShouldShowMFASplashScreen", 23),("UEnableMultiFactorModal::ShouldShowMFASplashScreen_HotfixVer", 0),("FrontendContext:ShouldShowSocialImport", 23),("FrontendContext:ShouldShowSocialImport_HotfixVer", 0))"""
-
Implement customizable parsing arguments.
-
Implement similar functions present in
parsecfg
.
-
Configuration File Object.
type Cfg* = OrderedTableRef[string, OrderedTableRef[string, string]]
- Functions
-
proc setSectionValue*(cfg: var Cfg, section, key, value: string)
Set the value of a key for the specified section.
-
proc delSection*(cfg: var Cfg, section: string)
Delete the specified section.
-
proc delSectionKey*(cfg: var Cfg, section, key: string)
Delete the specified key from a section.
-
proc getSectionValue*(cfg: Cfg, section, key: string, default: string = "")
Get the value of a key from the specified section.
-
- Functions
-
Create a new Configuration File Object.
proc newCfg*: Cfg
-
Load a Configuration File Object using a string or file.
-
String Representation
proc loadCfg*(str: string, case_sensitive: bool = true, delimiter: char = '=', comments: openArray[char] = [';']): Cfg
str
: String representation of the configuration file.caseSensitive
: Whether keys and sections should be case_senstive.delimiter
: The character used to separate keys from values.comments
: A sequence of characters used to indicate comments.
-
Filename
proc readCfg*(str: string, case_sensitive: bool = true, delimiter: char = '=', comments: openArray[char] = [';']): Cfg
filename
: Name of the file to read from.caseSensitive
: Whether keys and sections should be case_senstive.delimiter
: The character used to separate keys from values.comments
: A sequence of characters used to indicate comments.
-
-
Dump/Write a Configuration File Object as a string or file.
-
String Representation
proc dumpCfg*(cfg: Cfg, delimiter: char = '='): string
cfg
: Configuration File Objectdelimiter
: The character used to separate keys from values.
-
File
proc writeCfg*(cfg: Cfg, filename: string, delimiter: char = '=')
cfg
: Configuration File Objectfilename
: Name of the file write.delimiter
: The character used to separate keys from values.
-