Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a getter for all defined Sections in parsecfg #15450

Merged
merged 5 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Standard library additions and changes

- Added `sections` iterator in `parsecfg`.

- Make custom op in macros.quote work for all statements.

- On Windows the SSL library now checks for valid certificates.
Expand Down
6 changes: 6 additions & 0 deletions lib/pure/parsecfg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ runnableExamples:

import strutils, lexbase, streams, tables
import std/private/decode_helpers
import std/private/since

include "system/inclrtl"

Expand Down Expand Up @@ -649,3 +650,8 @@ proc delSectionKey*(dict: var Config, section, key: string) =
dict.del(section)
else:
dict[section].del(key)

iterator sections*(dict: Config): lent string {.since: (1, 5).} =
## Iterate throught the sections in the config
ringabout marked this conversation as resolved.
Show resolved Hide resolved
for section in dict.keys:
yield section
3 changes: 2 additions & 1 deletion tests/stdlib/tparsecfg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
targets: "c js"
"""

import parsecfg, streams
import parsecfg, streams, sequtils

when not defined(js):
from stdtest/specialpaths import buildDir
Expand Down Expand Up @@ -52,6 +52,7 @@ doAssert pname == "hello"
doAssert name == "lihf8515"
doAssert qq == "10214028"
doAssert email == "lihaifeng@wxm.com"
doAssert toSeq(dict2.sections) == @["", "Package", "Author"]

## Modifying a configuration file.
var dict3 = loadConfig(newStringStream(ss.data))
Expand Down