The strtabs
module implements an efficient hash table that is a mapping from strings to strings. Supports a case-sensitive, case-insensitive and style-insensitive mode. An efficient string substitution operator %
for the string table is also provided.
StringTableMode = enum modeCaseSensitive, ## the table is case sensitive modeCaseInsensitive, ## the table is case insensitive modeStyleInsensitive ## the table is style insensitive
StringTableObj = object of RootObj counter: int data: KeyValuePairSeq mode: StringTableMode
StringTableRef = ref StringTableObj
FormatFlag = enum useEnvironment, ## use environment variable if the ``$key`` ## is not found in the table. Does nothing when using `js` target. useEmpty, ## use the empty string as a default, thus it ## won't throw an exception if ``$key`` is not ## in the table useKey ## do not replace ``$key`` if it is not found ## in the table (or in the environment)
proc len(t: StringTableRef): int {.gcsafe, extern: "nst$1", raises: [], tags: [].}
proc `[]`(t: StringTableRef; key: string): var string {.gcsafe, extern: "nstTake", raises: [KeyError], tags: [].}
t[key]
. If key is not in t, the KeyError
exception is raised. One can check with hasKey
whether the key exists. proc mget(t: StringTableRef; key: string): var string {.deprecated, raises: [KeyError], tags: [].}
t[key]
. If key is not in t, the KeyError
exception is raised. Use ```[]``` instead. proc getOrDefault(t: StringTableRef; key: string; default: string = ""): string {. raises: [], tags: [].}
proc hasKey(t: StringTableRef; key: string): bool {.gcsafe, extern: "nst$1", raises: [], tags: [].}
proc `[]=`(t: StringTableRef; key, val: string) {.gcsafe, extern: "nstPut", raises: [], tags: [].}
proc newStringTable(mode: StringTableMode): StringTableRef {.gcsafe, extern: "nst$1", raises: [], tags: [].}
proc clear(s: StringTableRef; mode: StringTableMode) {.raises: [], tags: [].}
proc newStringTable(keyValuePairs: varargs[string]; mode: StringTableMode): StringTableRef {. gcsafe, extern: "nst$1WithPairs", raises: [], tags: [].}
var mytab = newStringTable("key1", "val1", "key2", "val2", modeCaseInsensitive)
proc newStringTable(keyValuePairs: varargs[tuple[key, val: string]]; mode: StringTableMode = modeCaseSensitive): StringTableRef {. gcsafe, extern: "nst$1WithTableConstr", raises: [], tags: [].}
var mytab = newStringTable({"key1": "val1", "key2": "val2"}, modeCaseInsensitive)
proc `%`(f: string; t: StringTableRef; flags: set[FormatFlag] = {}): string {. gcsafe, extern: "nstFormat", raises: [ValueError], tags: [ReadEnvEffect].}
proc `$`(t: StringTableRef): string {.gcsafe, extern: "nstDollar", raises: [], tags: [].}
iterator pairs(t: StringTableRef): tuple[key, value: string] {.raises: [], tags: [].}
iterator keys(t: StringTableRef): string {.raises: [], tags: [].}
iterator values(t: StringTableRef): string {.raises: [], tags: [].}
© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/strtabs.html