t17025.nim 1.4 KB

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