Module strtabs

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 Edit
StringTableObj = object of RootObj
  counter: int
  data: KeyValuePairSeq
  mode: StringTableMode
  Source Edit
StringTableRef = ref StringTableObj
use this type to declare string tables   Source Edit
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)
flags for the % operator   Source Edit

Procs

proc len(t: StringTableRef): int {.
gcsafe, extern: "nst$1", raises: [], tags: []
.}
returns the number of keys in t.   Source Edit
proc `[]`(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. One can check with hasKey whether the key exists.   Source Edit
proc mget(t: StringTableRef; key: string): var string {.
deprecated, raises: [KeyError], tags: []
.}
retrieves the location at t[key]. If key is not in t, the KeyError exception is raised. Use ```[]``` instead.   Source Edit
proc getOrDefault(t: StringTableRef; key: string): string {.
raises: [], tags: []
.}
  Source Edit
proc hasKey(t: StringTableRef; key: string): bool {.
gcsafe, extern: "nst$1", raises: [], tags: []
.}
returns true iff key is in the table t.   Source Edit
proc `[]=`(t: StringTableRef; key, val: string) {.
gcsafe, extern: "nstPut", raises: [], tags: []
.}
puts a (key, value)-pair into t.   Source Edit
proc newStringTable(mode: StringTableMode): StringTableRef {.
gcsafe, extern: "nst$1", raises: [], tags: []
.}
creates a new string table that is empty.   Source Edit
proc clear(s: StringTableRef; mode: StringTableMode) {.
raises: [], tags: []
.}
resets a string table to be empty again.   Source Edit
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 Edit
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 Edit
proc `%`(f: string; t: StringTableRef; flags: set[FormatFlag] = {}): string {.
gcsafe, extern: "nstFormat", raises: [ValueError], tags: [ReadEnvEffect]
.}
The % operator for string tables.   Source Edit
proc `$`(t: StringTableRef): string {.
gcsafe, extern: "nstDollar", raises: [], tags: []
.}
The $ operator for string tables.   Source Edit

Iterators

iterator pairs(t: StringTableRef): tuple[key, value: string] {.
raises: [], tags: []
.}
iterates over every (key, value) pair in the table t.   Source Edit
iterator keys(t: StringTableRef): string {.
raises: [], tags: []
.}
iterates over every key in the table t.   Source Edit
iterator values(t: StringTableRef): string {.
raises: [], tags: []
.}
iterates over every value in the table t.   Source Edit