Update parsecfg.nim (#15513)

* Update parsecfg.nim

Returns the specified default value if the specified key value does not exist.

* Update lib/pure/parsecfg.nim

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>

* Update lib/pure/parsecfg.nim

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>

* Update lib/pure/parsecfg.nim

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
This commit is contained in:
lihaifeng
2020-10-08 23:17:00 +08:00
committed by GitHub
parent 538a57a522
commit 3eaacac230

View File

@@ -560,15 +560,16 @@ proc writeConfig*(dict: Config, filename: string) =
let fileStream = newFileStream(file)
dict.writeConfig(fileStream)
proc getSectionValue*(dict: Config, section, key: string): string =
## Gets the Key value of the specified Section, returns an empty string if the key does not exist.
proc getSectionValue*(dict: Config, section, key: string, defaultVal = ""): string =
## Gets the key value of the specified Section.
## Returns the specified default value if the specified key does not exist.
if dict.hasKey(section):
if dict[section].hasKey(key):
result = dict[section][key]
else:
result = ""
result = defaultVal
else:
result = ""
result = defaultVal
proc setSectionKey*(dict: var Config, section, key, value: string) =
## Sets the Key value of the specified Section.