Skip to content

Commit

Permalink
Fix difference in spliting "key = val" and "key=val"
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmry committed Jan 20, 2023
1 parent 2714790 commit 695f128
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/configparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Section* = ref object
properties: Table[string, string]


proc setProperty*(this: Section, name: string, value: string) =
proc setProperty*(this: Section, name: string, value: sink string) =
this.properties[name] = value

proc newSection*() : Section =
Expand Down Expand Up @@ -43,8 +43,7 @@ proc hasSection*(this: Ini, name: string): bool =
proc deleteSection*(this: Ini, name:string) =
this.sections.del(name)

proc sectionsCount*(this: Ini) : int =
echo $this.sections
proc sectionsCount*(this: Ini) : int =
return len(this.sections)

proc hasProperty*(this: Ini, sectionName: string, key: string): bool=
Expand Down Expand Up @@ -110,20 +109,12 @@ proc parseIni*(s: string): Ini =
continue

if state == readKV:
let parts = line.split({'='})
var parts = line.split({'='}, 1)
if len(parts) == 2:
let key = parts[0].strip()
let val = parts[1].strip()
ini.setProperty(currentSectionName, key, val)
elif len(parts) > 2:
let key = parts[0].strip()
let val = line.replace(key & " =", "").strip()
var
key = strip(move parts[0])
val = strip(move parts[1])
ini.setProperty(currentSectionName, key, val)
else:
raise newException(ValueError, fmt("Expected line {line} to have key = value"))
return ini





0 comments on commit 695f128

Please sign in to comment.