Skip to content

Commit

Permalink
Update parsecfg.nim (#15513)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lihf8515 and ringabout authored Oct 8, 2020
1 parent 538a57a commit 3eaacac
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/pure/parsecfg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3eaacac

Please sign in to comment.