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.
TStringTableMode* = enum
modeCaseSensitive,
modeCaseInsensitive,
modeStyleInsensitive
-
describes the tables operation mode
TStringTable* = object of TObject
counter: int
data: TKeyValuePairSeq
mode: TStringTableMode
-
PStringTable* = ref TStringTable
-
use this type to declare string tables
TFormatFlag* = enum
useEnvironment,
useEmpty,
useKey
-
flags for the % operator
proc len*(t: PStringTable): int {.rtl, extern: "nst$1".}
-
returns the number of keys in t.
proc `[]`*(t: PStringTable; key: string): string {.rtl, extern: "nstGet".}
-
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.
proc mget*(t: PStringTable; key: string): var string {.rtl, extern: "nstTake".}
-
retrieves the location at t[key]. If key is not in t, the EInvalidKey exception is raised.
proc hasKey*(t: PStringTable; key: string): bool {.rtl, extern: "nst$1".}
-
returns true iff key is in the table t.
proc `[] =`*(t: PStringTable; key, val: string) {.rtl, extern: "nstPut".}
-
puts a (key, value)-pair into t.
proc newStringTable*(mode: TStringTableMode): PStringTable {.rtl,
extern: "nst$1".}
-
creates a new string table that is empty.
proc newStringTable*(keyValuePairs: varargs[string]; mode: TStringTableMode): PStringTable {.
rtl, extern: "nst$1WithPairs".}
-
creates a new string table with given key value pairs. Example:
var mytab = newStringTable("key1", "val1", "key2", "val2",
modeCaseInsensitive)
proc newStringTable*(keyValuePairs: varargs[tuple[key, val: string]];
mode: TStringTableMode = modeCaseSensitive): PStringTable {.
rtl, extern: "nst$1WithTableConstr".}
-
creates a new string table with given key value pairs. Example:
var mytab = newStringTable({"key1": "val1", "key2": "val2"},
modeCaseInsensitive)
proc `%`*(f: string; t: PStringTable; flags: set[TFormatFlag] = {}): string {.
rtl, extern: "nstFormat".}
-
The % operator for string tables.
proc `$`*(t: PStringTable): string {.rtl, extern: "nstDollar".}
-
The $ operator for string tables.
iterator pairs*(t: PStringTable): tuple[key, value: string]
-
iterates over any (key, value) pair in the table t.