diff options
Diffstat (limited to 'lib/pure/strtabs.nim')
-rwxr-xr-x | lib/pure/strtabs.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index 2028daa50..584282fbc 100755 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -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" |