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.
Types
StringTableMode = enum modeCaseSensitive, ## the table is case sensitive modeCaseInsensitive, ## the table is case insensitive modeStyleInsensitive ## the table is style insensitive
- describes the tables operation mode Source
StringTableObj = object of RootObj counter: int data: KeyValuePairSeq mode: StringTableMode
- Source
StringTableRef = ref StringTableObj
- use this type to declare string tables Source
FormatFlag = enum useEnvironment, ## use environment variable if the ``$key`` ## is not found in the table 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)
- flags for the % operator Source
Procs
proc len(t: StringTableRef): int {.gcsafe, extern: "nst$1", raises: [], tags: [].}
- returns the number of keys in t. Source
proc `[]`(t: StringTableRef; key: string): string {.gcsafe, extern: "nstGet", raises: [], tags: [].}
- retrieves the value at t[key]. If key is not in t, "" is returned and no exception is raised. One can check with hasKey whether the key exists. Source
proc mget(t: StringTableRef; key: string): var string {.gcsafe, extern: "nstTake", raises: [KeyError], tags: [].}
- retrieves the location at t[key]. If key is not in t, the KeyError exception is raised. Source
proc hasKey(t: StringTableRef; key: string): bool {.gcsafe, extern: "nst$1", raises: [], tags: [].}
- returns true iff key is in the table t. Source
proc `[]=`(t: StringTableRef; key, val: string) {.gcsafe, extern: "nstPut", raises: [], tags: [].}
- puts a (key, value)-pair into t. Source
proc newStringTable(mode: StringTableMode): StringTableRef {.gcsafe, extern: "nst$1", raises: [], tags: [].}
- creates a new string table that is empty. Source
proc clear(s: StringTableRef; mode: StringTableMode) {.raises: [], tags: [].}
- resets a string table to be empty again. Source
proc newStringTable(keyValuePairs: varargs[string]; mode: StringTableMode): StringTableRef {. gcsafe, extern: "nst$1WithPairs", raises: [], tags: [].}
-
creates a new string table with given key value pairs. Example:
var mytab = newStringTable("key1", "val1", "key2", "val2", modeCaseInsensitive)
Source proc newStringTable(keyValuePairs: varargs[tuple[key, val: string]]; mode: StringTableMode = modeCaseSensitive): StringTableRef {. gcsafe, extern: "nst$1WithTableConstr", raises: [], tags: [].}
-
creates a new string table with given key value pairs. Example:
var mytab = newStringTable({"key1": "val1", "key2": "val2"}, modeCaseInsensitive)
Source proc `%`(f: string; t: StringTableRef; flags: set[FormatFlag] = {}): string {. gcsafe, extern: "nstFormat", raises: [ValueError], tags: [ReadEnvEffect].}
- The % operator for string tables. Source
proc `$`(t: StringTableRef): string {.gcsafe, extern: "nstDollar", raises: [], tags: [].}
- The $ operator for string tables. Source
Iterators
iterator pairs(t: StringTableRef): tuple[key, value: string] {.raises: [], tags: [].}
- iterates over every (key, value) pair in the table t. Source
iterator keys(t: StringTableRef): string {.raises: [], tags: [].}
- iterates over every key in the table t. Source
iterator values(t: StringTableRef): string {.raises: [], tags: [].}
- iterates over every value in the table t. Source