123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/strtabs</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
- <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/strtabs</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#FormatFlag" title="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).">FormatFlag</a></li>
- <li><a class="reference" href="#StringTableMode" title="StringTableMode = enum
- modeCaseSensitive, ## the table is case sensitive
- modeCaseInsensitive, ## the table is case insensitive
- modeStyleInsensitive ## the table is style insensitive">StringTableMode</a></li>
- <li><a class="reference" href="#StringTableObj" title="StringTableObj = object of RootObj">StringTableObj</a></li>
- <li><a class="reference" href="#StringTableRef" title="StringTableRef = ref StringTableObj">StringTableRef</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">$
- <li><a class="reference" href="#%24%2CStringTableRef" title="`$`(t: StringTableRef): string">`$`(t: StringTableRef): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">%
- <li><a class="reference" href="#%25%2Cstring%2CStringTableRef%2Cset%5BFormatFlag%5D" title="`%`(f: string; t: StringTableRef; flags: set[FormatFlag] = {}): string">`%`(f: string; t: StringTableRef; flags: set[FormatFlag] = {}): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">[]
- <li><a class="reference" href="#%5B%5D%2CStringTableRef%2Cstring" title="`[]`(t: StringTableRef; key: string): var string">`[]`(t: StringTableRef; key: string): var string</a></li>
- </ul>
- <ul class="simple nested-toc-section">[]=
- <li><a class="reference" href="#%5B%5D%3D%2CStringTableRef%2Cstring%2Cstring" title="`[]=`(t: StringTableRef; key, val: string)">`[]=`(t: StringTableRef; key, val: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">clear
- <li><a class="reference" href="#clear%2CStringTableRef" title="clear(s: StringTableRef)">clear(s: StringTableRef)</a></li>
- <li><a class="reference" href="#clear%2CStringTableRef%2CStringTableMode" title="clear(s: StringTableRef; mode: StringTableMode)">clear(s: StringTableRef; mode: StringTableMode)</a></li>
- </ul>
- <ul class="simple nested-toc-section">contains
- <li><a class="reference" href="#contains%2CStringTableRef%2Cstring" title="contains(t: StringTableRef; key: string): bool">contains(t: StringTableRef; key: string): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">del
- <li><a class="reference" href="#del%2CStringTableRef%2Cstring" title="del(t: StringTableRef; key: string)">del(t: StringTableRef; key: string)</a></li>
- </ul>
- <ul class="simple nested-toc-section">getOrDefault
- <li><a class="reference" href="#getOrDefault%2CStringTableRef%2Cstring%2Cstring" title="getOrDefault(t: StringTableRef; key: string; default: string = ""): string">getOrDefault(t: StringTableRef; key: string; default: string = ""): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">hasKey
- <li><a class="reference" href="#hasKey%2CStringTableRef%2Cstring" title="hasKey(t: StringTableRef; key: string): bool">hasKey(t: StringTableRef; key: string): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">len
- <li><a class="reference" href="#len%2CStringTableRef" title="len(t: StringTableRef): int">len(t: StringTableRef): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">mode
- <li><a class="reference" href="#mode%2CStringTableRef" title="mode(t: StringTableRef): StringTableMode">mode(t: StringTableRef): StringTableMode</a></li>
- </ul>
- <ul class="simple nested-toc-section">newStringTable
- <li><a class="reference" href="#newStringTable%2Cvarargs%5Bstring%5D%2CStringTableMode" title="newStringTable(keyValuePairs: varargs[string]; mode: StringTableMode): owned(
- StringTableRef)">newStringTable(keyValuePairs: varargs[string]; mode: StringTableMode): owned(
- StringTableRef)</a></li>
- <li><a class="reference" href="#newStringTable%2Cvarargs%5Btuple%5Bstring%2Cstring%5D%5D%2CStringTableMode" title="newStringTable(keyValuePairs: varargs[tuple[key, val: string]];
- mode: StringTableMode = modeCaseSensitive): owned(StringTableRef)">newStringTable(keyValuePairs: varargs[tuple[key, val: string]];
- mode: StringTableMode = modeCaseSensitive): owned(StringTableRef)</a></li>
- <li><a class="reference" href="#newStringTable%2CStringTableMode" title="newStringTable(mode: StringTableMode): owned(StringTableRef)">newStringTable(mode: StringTableMode): owned(StringTableRef)</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">keys
- <li><a class="reference" href="#keys.i%2CStringTableRef" title="keys(t: StringTableRef): string">keys(t: StringTableRef): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">pairs
- <li><a class="reference" href="#pairs.i%2CStringTableRef" title="pairs(t: StringTableRef): tuple[key, value: string]">pairs(t: StringTableRef): tuple[key, value: string]</a></li>
- </ul>
- <ul class="simple nested-toc-section">values
- <li><a class="reference" href="#values.i%2CStringTableRef" title="values(t: StringTableRef): string">values(t: StringTableRef): string</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <p class="module-desc">The <tt class="docutils literal"><span class="pre">strtabs</span></tt> module implements an efficient hash table that is a mapping from strings to strings. Supports a case-sensitive, case-insensitive and style-insensitive mode.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strtabs</span>
- <span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Identifier">newStringTable</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">t</span><span class="Punctuation">[</span><span class="StringLit">"name"</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="StringLit">"John"</span>
- <span class="Identifier">t</span><span class="Punctuation">[</span><span class="StringLit">"city"</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="StringLit">"Monaco"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">hasKey</span> <span class="StringLit">"name"</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"name"</span> <span class="Keyword">in</span> <span class="Identifier">t</span></pre>String tables can be created from a table constructor:
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strtabs</span>
- <span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span></pre>When using the style insensitive mode (<tt class="docutils literal"><span class="pre">modeStyleInsensitive</span></tt>), all letters are compared case insensitively within the ASCII range and underscores are ignored.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strtabs</span>
- <span class="Keyword">var</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="Identifier">newStringTable</span><span class="Punctuation">(</span><span class="Identifier">modeStyleInsensitive</span><span class="Punctuation">)</span>
- <span class="Identifier">x</span><span class="Punctuation">[</span><span class="StringLit">"first_name"</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="StringLit">"John"</span>
- <span class="Identifier">x</span><span class="Punctuation">[</span><span class="StringLit">"LastName"</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="StringLit">"Doe"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">x</span><span class="Punctuation">[</span><span class="StringLit">"firstName"</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">"John"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">x</span><span class="Punctuation">[</span><span class="StringLit">"last_name"</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">"Doe"</span></pre>An efficient string substitution operator <a class="reference external" href="#%25,string,StringTableRef,set[FormatFlag]">%</a> for the string table is also provided.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strtabs</span>
- <span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"${name} lives in ${city}"</span> <span class="Operator">%</span> <span class="Identifier">t</span> <span class="Operator">==</span> <span class="StringLit">"John lives in Monaco"</span></pre><strong>See also:</strong><ul class="simple"><li><a class="reference external" href="tables.html">tables module</a> for general hash tables</li>
- <li><a class="reference external" href="sharedtables.html">sharedtables module</a> for shared hash table support</li>
- <li><a class="reference external" href="strutils.html">strutils module</a> for common string functions</li>
- <li><a class="reference external" href="json.html">json module</a> for table-like structure which allows heterogeneous members</li>
- </ul>
- </p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="since.html">since</a>, <a class="reference external" href="hashes.html">hashes</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="envvars.html">envvars</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="FormatFlag">
- <dt><pre><a href="strtabs.html#FormatFlag"><span class="Identifier">FormatFlag</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">useEnvironment</span><span class="Other">,</span> <span class="Comment">## Use environment variable if the ``$key``</span>
- <span class="Comment">## is not found in the table.</span>
- <span class="Comment">## Does nothing when using `js` target.</span>
- <span class="Identifier">useEmpty</span><span class="Other">,</span> <span class="Comment">## Use the empty string as a default, thus it</span>
- <span class="Comment">## won't throw an exception if ``$key`` is not</span>
- <span class="Comment">## in the table.</span>
- <span class="Identifier">useKey</span> <span class="Comment">## Do not replace ``$key`` if it is not found</span>
- <span class="Comment">## in the table (or in the environment).</span></pre></dt>
- <dd>
-
- Flags for the <tt class="docutils literal"><span class="pre"><span class="Operator">%</span></span></tt> operator.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L82" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L82" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="StringTableMode">
- <dt><pre><a href="strtabs.html#StringTableMode"><span class="Identifier">StringTableMode</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">modeCaseSensitive</span><span class="Other">,</span> <span class="Comment">## the table is case sensitive</span>
- <span class="Identifier">modeCaseInsensitive</span><span class="Other">,</span> <span class="Comment">## the table is case insensitive</span>
- <span class="Identifier">modeStyleInsensitive</span> <span class="Comment">## the table is style insensitive</span></pre></dt>
- <dd>
-
- Describes the tables operation mode.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L69" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L69" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="StringTableObj">
- <dt><pre><a href="strtabs.html#StringTableObj"><span class="Identifier">StringTableObj</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="system.html#RootObj"><span class="Identifier">RootObj</span></a></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L75" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L75" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="StringTableRef">
- <dt><pre><a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <a href="strtabs.html#StringTableObj"><span class="Identifier">StringTableObj</span></a></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L80" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L80" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="$-procs-all">
- <div id="$,StringTableRef">
- <dt><pre><span class="Keyword">proc</span> <a href="#%24%2CStringTableRef"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nstDollar"</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- The <tt class="docutils literal"><span class="pre"><span class="Operator">$</span></span></tt> operator for string tables. Used internally when calling <tt class="docutils literal"><span class="pre"><span class="Identifier">echo</span></span></tt> on a table.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L376" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L376" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="%-procs-all">
- <div id="%,string,StringTableRef,set[FormatFlag]">
- <dt><pre><span class="Keyword">proc</span> <a href="#%25%2Cstring%2CStringTableRef%2Cset%5BFormatFlag%5D"><span class="Identifier">`%`</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">flags</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="strtabs.html#FormatFlag"><span class="Identifier">FormatFlag</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Other">{</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nstFormat"</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadEnvEffect</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- The <tt class="docutils literal"><span class="pre"><span class="Operator">%</span></span></tt> operator for string tables.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"${name} lives in ${city}"</span> <span class="Operator">%</span> <span class="Identifier">t</span> <span class="Operator">==</span> <span class="StringLit">"John lives in Monaco"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L390" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L390" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="[]-procs-all">
- <div id="[],StringTableRef,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CStringTableRef%2Cstring"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
- <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nstTake"</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Retrieves the location at <tt class="docutils literal"><span class="pre">t[key]</span></tt>.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is not in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>, the <tt class="docutils literal"><span class="pre">KeyError</span></tt> exception is raised. One can check with <a class="reference external" href="#hasKey,StringTableRef,string">hasKey proc</a> whether the key exists.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#getOrDefault,StringTableRef,string,string">getOrDefault proc</a></li>
- <li><a class="reference external" href="#[]=,StringTableRef,string,string">[]= proc</a> for inserting a new (key, value) pair in the table</li>
- <li><a class="reference external" href="#hasKey,StringTableRef,string">hasKey proc</a> for checking if a key is in the table</li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Punctuation">[</span><span class="StringLit">"name"</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">"John"</span>
- <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">KeyError</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
- <span class="Identifier">echo</span> <span class="Identifier">t</span><span class="Punctuation">[</span><span class="StringLit">"occupation"</span><span class="Punctuation">]</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L155" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L155" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="[]=-procs-all">
- <div id="[]=,StringTableRef,string,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%3D%2CStringTableRef%2Cstring%2Cstring"><span class="Identifier">`[]=`</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">,</span> <span class="Identifier">val</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nstPut"</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Inserts a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">)</span></span></tt> pair into <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#[],StringTableRef,string">[] proc</a> for retrieving a value of a key</li>
- <li><a class="reference external" href="#del,StringTableRef,string">del proc</a> for removing a key from the table</li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">t</span><span class="Punctuation">[</span><span class="StringLit">"occupation"</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="StringLit">"teacher"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">hasKey</span><span class="Punctuation">(</span><span class="StringLit">"occupation"</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L237" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L237" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="clear-procs-all">
- <div id="clear,StringTableRef">
- <dt><pre><span class="Keyword">proc</span> <a href="#clear%2CStringTableRef"><span class="Identifier">clear</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Resets a string table to be empty again without changing the mode.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L331" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L331" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="clear,StringTableRef,StringTableMode">
- <dt><pre><span class="Keyword">proc</span> <a href="#clear%2CStringTableRef%2CStringTableMode"><span class="Identifier">clear</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">mode</span><span class="Other">:</span> <a href="strtabs.html#StringTableMode"><span class="Identifier">StringTableMode</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nst$1"</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Resets a string table to be empty again, perhaps altering the mode.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#del,StringTableRef,string">del proc</a> for removing a key from the table</li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Identifier">t</span><span class="Punctuation">,</span> <span class="Identifier">modeCaseSensitive</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">t</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"name"</span> <span class="Keyword">notin</span> <span class="Identifier">t</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"city"</span> <span class="Keyword">notin</span> <span class="Identifier">t</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L313" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L313" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="contains-procs-all">
- <div id="contains,StringTableRef,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#contains%2CStringTableRef%2Cstring"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Alias of <a class="reference external" href="#hasKey,StringTableRef,string">hasKey proc</a> for use with the <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"name"</span> <span class="Keyword">in</span> <span class="Identifier">t</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"occupation"</span> <span class="Keyword">notin</span> <span class="Identifier">t</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L213" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L213" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="del-procs-all">
- <div id="del,StringTableRef,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#del%2CStringTableRef%2Cstring"><span class="Identifier">del</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Removes <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> from <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#clear,StringTableRef,StringTableMode">clear proc</a> for resetting a table to be empty</li>
- <li><a class="reference external" href="#[]=,StringTableRef,string,string">[]= proc</a> for inserting a new (key, value) pair in the table</li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">del</span><span class="Punctuation">(</span><span class="StringLit">"name"</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">t</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"name"</span> <span class="Keyword">notin</span> <span class="Identifier">t</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"city"</span> <span class="Keyword">in</span> <span class="Identifier">t</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L335" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L335" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getOrDefault-procs-all">
- <div id="getOrDefault,StringTableRef,string,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#getOrDefault%2CStringTableRef%2Cstring%2Cstring"><span class="Identifier">getOrDefault</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">default</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">""</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Retrieves the location at <tt class="docutils literal"><span class="pre">t[key]</span></tt>.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is not in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>, the default value is returned (if not specified, it is an empty string (<tt class="docutils literal"><span class="pre"><span class="StringLit">""</span></span></tt>)).</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#[],StringTableRef,string">[] proc</a> for retrieving a value of a key</li>
- <li><a class="reference external" href="#hasKey,StringTableRef,string">hasKey proc</a> for checking if a key is in the table</li>
- <li><a class="reference external" href="#[]=,StringTableRef,string,string">[]= proc</a> for inserting a new (key, value) pair in the table</li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">getOrDefault</span><span class="Punctuation">(</span><span class="StringLit">"name"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"John"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">getOrDefault</span><span class="Punctuation">(</span><span class="StringLit">"occupation"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">""</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">getOrDefault</span><span class="Punctuation">(</span><span class="StringLit">"occupation"</span><span class="Punctuation">,</span> <span class="StringLit">"teacher"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"teacher"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">getOrDefault</span><span class="Punctuation">(</span><span class="StringLit">"name"</span><span class="Punctuation">,</span> <span class="StringLit">"Paul"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"John"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L176" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L176" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="hasKey-procs-all">
- <div id="hasKey,StringTableRef,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#hasKey%2CStringTableRef%2Cstring"><span class="Identifier">hasKey</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nst$1"</span><span class="Other">,</span>
- <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is in the table <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#getOrDefault,StringTableRef,string,string">getOrDefault proc</a></li>
- <li><a class="reference external" href="#contains,StringTableRef,string">contains proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">t</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">"name"</span><span class="Punctuation">:</span> <span class="StringLit">"John"</span><span class="Punctuation">,</span> <span class="StringLit">"city"</span><span class="Punctuation">:</span> <span class="StringLit">"Monaco"</span><span class="Punctuation">}</span><span class="Operator">.</span><span class="Identifier">newStringTable</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">hasKey</span><span class="Punctuation">(</span><span class="StringLit">"name"</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">t</span><span class="Operator">.</span><span class="Identifier">hasKey</span><span class="Punctuation">(</span><span class="StringLit">"occupation"</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L200" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L200" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="len-procs-all">
- <div id="len,StringTableRef">
- <dt><pre><span class="Keyword">proc</span> <a href="#len%2CStringTableRef"><span class="Identifier">len</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nst$1"</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Returns the number of keys in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L151" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L151" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="mode-procs-all">
- <div id="mode,StringTableRef">
- <dt><pre><span class="Keyword">proc</span> <a href="#mode%2CStringTableRef"><span class="Identifier">mode</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">)</span><span class="Other">:</span> <a href="strtabs.html#StringTableMode"><span class="Identifier">StringTableMode</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L96" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L96" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="newStringTable-procs-all">
- <div id="newStringTable,varargs[string],StringTableMode">
- <dt><pre><span class="Keyword">proc</span> <a href="#newStringTable%2Cvarargs%5Bstring%5D%2CStringTableMode"><span class="Identifier">newStringTable</span></a><span class="Other">(</span><span class="Identifier">keyValuePairs</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">mode</span><span class="Other">:</span> <a href="strtabs.html#StringTableMode"><span class="Identifier">StringTableMode</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <span class="Identifier">StringTableRef</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nst$1WithPairs"</span><span class="Other">,</span> </span><span class="Identifier">noSideEffect</span><span class="Other">,</span>
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new string table with given <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">value</span></span></tt> string pairs.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">StringTableMode</span></span></tt> must be specified.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">mytab</span> <span class="Operator">=</span> <span class="Identifier">newStringTable</span><span class="Punctuation">(</span><span class="StringLit">"key1"</span><span class="Punctuation">,</span> <span class="StringLit">"val1"</span><span class="Punctuation">,</span> <span class="StringLit">"key2"</span><span class="Punctuation">,</span> <span class="StringLit">"val2"</span><span class="Punctuation">,</span>
- <span class="Identifier">modeCaseInsensitive</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L266" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L266" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="newStringTable,varargs[tuple[string,string]],StringTableMode">
- <dt><pre><span class="Keyword">proc</span> <a href="#newStringTable%2Cvarargs%5Btuple%5Bstring%2Cstring%5D%5D%2CStringTableMode"><span class="Identifier">newStringTable</span></a><span class="Other">(</span><span class="Identifier">keyValuePairs</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">key</span><span class="Other">,</span> <span class="Identifier">val</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">]</span><span class="Other">;</span>
- <span class="Identifier">mode</span><span class="Other">:</span> <a href="strtabs.html#StringTableMode"><span class="Identifier">StringTableMode</span></a> <span class="Other">=</span> <span class="Identifier">modeCaseSensitive</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span>
- <span class="Identifier">StringTableRef</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nst$1WithTableConstr"</span><span class="Other">,</span> </span><span class="Identifier">noSideEffect</span><span class="Other">,</span>
- <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new string table with given <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">)</span></span></tt> tuple pairs.</p>
- <p>The default mode is case sensitive.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span>
- <span class="Identifier">mytab1</span> <span class="Operator">=</span> <span class="Identifier">newStringTable</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">"key1"</span><span class="Punctuation">:</span> <span class="StringLit">"val1"</span><span class="Punctuation">,</span> <span class="StringLit">"key2"</span><span class="Punctuation">:</span> <span class="StringLit">"val2"</span><span class="Punctuation">}</span><span class="Punctuation">,</span> <span class="Identifier">modeCaseInsensitive</span><span class="Punctuation">)</span>
- <span class="Identifier">mytab2</span> <span class="Operator">=</span> <span class="Identifier">newStringTable</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="StringLit">"key3"</span><span class="Punctuation">,</span> <span class="StringLit">"val3"</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="StringLit">"key4"</span><span class="Punctuation">,</span> <span class="StringLit">"val4"</span><span class="Punctuation">)</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L283" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L283" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="newStringTable,StringTableMode">
- <dt><pre><span class="Keyword">proc</span> <a href="#newStringTable%2CStringTableMode"><span class="Identifier">newStringTable</span></a><span class="Other">(</span><span class="Identifier">mode</span><span class="Other">:</span> <a href="strtabs.html#StringTableMode"><span class="Identifier">StringTableMode</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">StringTableRef</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
- <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">"nst$1"</span><span class="Other">,</span> </span><span class="Identifier">noSideEffect</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new empty string table.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#newStringTable,varargs[tuple[string,string]],StringTableMode">newStringTable(keyValuePairs) proc</a></li>
- </ul>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L257" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L257" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="15">
- <h1><a class="toc-backref" href="#15">Iterators</a></h1>
- <dl class="item">
- <div id="keys-iterators-all">
- <div id="keys.i,StringTableRef">
- <dt><pre><span class="Keyword">iterator</span> <a href="#keys.i%2CStringTableRef"><span class="Identifier">keys</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Iterates over every key in the table <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L104" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L104" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="pairs-iterators-all">
- <div id="pairs.i,StringTableRef">
- <dt><pre><span class="Keyword">iterator</span> <a href="#pairs.i%2CStringTableRef"><span class="Identifier">pairs</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">key</span><span class="Other">,</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Iterates over every <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">)</span></span></tt> pair in the table <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L98" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L98" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="values-iterators-all">
- <div id="values.i,StringTableRef">
- <dt><pre><span class="Keyword">iterator</span> <a href="#values.i%2CStringTableRef"><span class="Identifier">values</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="strtabs.html#StringTableRef"><span class="Identifier">StringTableRef</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Iterates over every value in the table <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strtabs.nim#L110" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strtabs.nim#L110" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-01-09 12:00:16 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|