added getOrDefault; bootstrapping works again

This commit is contained in:
Araq 2015-10-13 03:03:05 +02:00
commit 2fda95a4d6
9 changed files with 52 additions and 40 deletions

View file

@ -122,6 +122,11 @@ proc mget*(t: StringTableRef, key: string): var string {.deprecated.} =
## ``KeyError`` exception is raised. Use ```[]``` instead.
get(t, key)
proc getOrDefault*(t: StringTableRef; key: string): string =
var index = rawGet(t, key)
if index >= 0: result = t.data[index].val
else: result = ""
proc hasKey*(t: StringTableRef, key: string): bool {.rtl, extern: "nst$1".} =
## returns true iff `key` is in the table `t`.
result = rawGet(t, key) >= 0