bugfixes; step one for 'var T' as return type support
This commit is contained in:
parent
e7135c449d
commit
2f066395ba
27 changed files with 234 additions and 68 deletions
|
|
@ -92,6 +92,14 @@ proc `[]`*(t: PStringTable, key: string): string {.rtl, extern: "nstGet".} =
|
|||
if index >= 0: result = t.data[index].val
|
||||
else: result = ""
|
||||
|
||||
proc modGet*(t: PStringTable, key: string): var string {.
|
||||
rtl, extern: "nstTake".} =
|
||||
## retrieves the location at ``t[key]``. If `key` is not in `t`, the
|
||||
## ``EInvalidValue`` exception is raised.
|
||||
var index = RawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
else: raise newException(EInvalidValue, "key does not exist: " & key)
|
||||
|
||||
proc hasKey*(t: PStringTable, key: string): bool {.rtl, extern: "nst$1".} =
|
||||
## returns true iff `key` is in the table `t`.
|
||||
result = rawGet(t, key) >= 0
|
||||
|
|
@ -213,4 +221,6 @@ when isMainModule:
|
|||
assert x["k"] == "v"
|
||||
assert x["11"] == "22"
|
||||
assert x["565"] == "67"
|
||||
x.modGet("11") = "23"
|
||||
assert x["11"] == "23"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue