1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
discard """
cmd: "nim c --gc:arc $file"
output: '''
{"Package": {"name": "hello"}, "Author": {"name": "name", "qq": "123456789", "email": "email"}}
hello
name
123456789
email
hello
name2
987654321
liame
'''
"""
import parsecfg, streams, tables
const cfg = """[Package]
name=hello
[Author]
name=name
qq=123456789
email="email""""
proc main() =
let stream = newStringStream(cfg)
let dict = loadConfig(stream)
var pname = dict.getSectionValue("Package","name")
var name = dict.getSectionValue("Author","name")
var qq = dict.getSectionValue("Author","qq")
var email = dict.getSectionValue("Author","email")
echo dict[]
echo pname & "\n" & name & "\n" & qq & "\n" & email
stream.close()
main()
proc getDict(): OrderedTableRef[string, OrderedTableRef[string, string]] =
result = newOrderedTable[string, OrderedTableRef[string, string]]()
result["Package"] = newOrderedTable[string, string]()
result["Package"]["name"] = "hello"
result["Author"] = newOrderedTable[string, string]()
result["Author"]["name"] = "name2"
result["Author"]["qq"] = "987654321"
result["Author"]["email"] = "liame"
proc main2() =
let dict = getDict()
var pname = dict.getSectionValue("Package","name")
var name = dict.getSectionValue("Author","name")
var qq = dict.getSectionValue("Author","qq")
var email = dict.getSectionValue("Author","email")
echo pname & "\n" & name & "\n" & qq & "\n" & email
main2()
|