diff options
author | Ico Doornekamp <github@zevv.nl> | 2019-01-07 00:52:19 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-01-07 00:52:19 +0100 |
commit | be9d1280ae39b64e6c76179a788034ad6c50a52d (patch) | |
tree | f1ea9f1977c7911c071ca5fb34ae105a4c41c5c0 /lib/pure | |
parent | e77dd683eb9b6b2b9c2638f4145f8857fece12cb (diff) | |
download | Nim-be9d1280ae39b64e6c76179a788034ad6c50a52d.tar.gz |
Added examples to strtabs module (#10160)
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/strtabs.nim | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index d8a23286a..7bafe1675 100644 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -12,6 +12,34 @@ ## style-insensitive mode. An efficient string substitution operator ``%`` ## for the string table is also provided. +runnableExamples: + + var t = newStringTable() + t["name"] = "John" + t["city"] = "Monaco" + doAssert t.len == 2 + doAssert t.hasKey "name" + doAssert "name" in t + +## String tables can be created from a table constructor: + +runnableExamples: + var t = {"name": "John", "city": "Monaco"}.newStringTable + + +## When using the style insensitive mode ``modeStyleInsensitive``, +## all letters are compared case insensitively within the ASCII range +## and underscores are ignored. + +runnableExamples: + + var x = newStringTable(modeStyleInsensitive) + x["first_name"] = "John" + x["LastName"] = "Doe" + + doAssert x["firstName"] == "John" + doAssert x["last_name"] == "Doe" + import hashes, strutils @@ -214,6 +242,9 @@ proc newStringTable*(keyValuePairs: varargs[tuple[key, val: string]], proc `%`*(f: string, t: StringTableRef, flags: set[FormatFlag] = {}): string {. rtlFunc, extern: "nstFormat".} = ## The `%` operator for string tables. + runnableExamples: + var t = {"name": "John", "city": "Monaco"}.newStringTable + doAssert "${name} lives in ${city}" % t == "John lives in Monaco" const PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'} result = "" |