mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
added default param to strtabs.getOrDefault (#5280)
This commit is contained in:
committed by
Andreas Rumpf
parent
7f30d04d6a
commit
b20817c3fb
@@ -129,10 +129,10 @@ 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 =
|
||||
proc getOrDefault*(t: StringTableRef; key: string, default: string = ""): string =
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
else: result = ""
|
||||
else: result = default
|
||||
|
||||
proc hasKey*(t: StringTableRef, key: string): bool {.rtlFunc, extern: "nst$1".} =
|
||||
## returns true iff `key` is in the table `t`.
|
||||
|
||||
Reference in New Issue
Block a user