strformat.html 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/strformat</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <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=="/>
  14. <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=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/strformat</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li><a class="reference" id="nimfmt-vsdot-nimamp_toc" href="#nimfmt-vsdot-nimamp"><tt class="docutils literal"><span class="pre"><span class="Identifier">fmt</span></span></tt> vs. <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt></a></li>
  50. <li><a class="reference" id="formatting-strings_toc" href="#formatting-strings">Formatting strings</a></li>
  51. <li><a class="reference" id="formatting-floats_toc" href="#formatting-floats">Formatting floats</a></li>
  52. <li><a class="reference" id="expressions_toc" href="#expressions">Expressions</a></li>
  53. <li><a class="reference" id="debugging-strings_toc" href="#debugging-strings">Debugging strings</a></li>
  54. <li><a class="reference" id="implementation-details_toc" href="#implementation-details">Implementation details</a></li>
  55. <li><a class="reference" id="standard-format-specifiers-for-strings-integers-and-floats_toc" href="#standard-format-specifiers-for-strings-integers-and-floats">Standard format specifiers for strings, integers and floats</a></li>
  56. <li><a class="reference" id="limitations_toc" href="#limitations">Limitations</a></li>
  57. <li><a class="reference" id="future-directions_toc" href="#future-directions">Future directions</a></li>
  58. <li>
  59. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  60. </li>
  61. <li>
  62. <details open>
  63. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  64. <ul class="simple simple-toc-section">
  65. <li><a class="reference" href="#StandardFormatSpecifier" title="StandardFormatSpecifier = object
  66. fill*, align*: char ## Desired fill and alignment.
  67. sign*: char ## Desired sign.
  68. alternateForm*: bool ## Whether to prefix binary, octal and hex numbers
  69. ## with `0b`, `0o`, `0x`.
  70. padWithZero*: bool ## Whether to pad with zeros rather than spaces.
  71. minimumWidth*, precision*: int ## Desired minimum width and precision.
  72. typ*: char ## Type like 'f', 'g' or 'd'.
  73. endPosition*: int ## End position in the format specifier after
  74. ## `parseStandardFormatSpecifier` returned.">StandardFormatSpecifier</a></li>
  75. </ul>
  76. </details>
  77. </li>
  78. <li>
  79. <details open>
  80. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  81. <ul class="simple simple-toc-section">
  82. <ul class="simple nested-toc-section">alignString
  83. <li><a class="reference" href="#alignString%2Cstring%2Cint%2Cchar%2Cchar" title="alignString(s: string; minimumWidth: int; align = '\x00'; fill = ' '): string">alignString(s: string; minimumWidth: int; align = '\x00'; fill = ' '): string</a></li>
  84. </ul>
  85. <ul class="simple nested-toc-section">formatValue
  86. <li><a class="reference" href="#formatValue%2Cstring%2CSomeFloat%2Cstaticstring" title="formatValue(result: var string; value: SomeFloat; specifier: static string)">formatValue(result: var string; value: SomeFloat; specifier: static string)</a></li>
  87. <li><a class="reference" href="#formatValue%2Cstring%2CSomeFloat%2Cstring" title="formatValue(result: var string; value: SomeFloat; specifier: string)">formatValue(result: var string; value: SomeFloat; specifier: string)</a></li>
  88. <li><a class="reference" href="#formatValue%2Cstring%2Cstring%2Cstaticstring" title="formatValue(result: var string; value: string; specifier: static string)">formatValue(result: var string; value: string; specifier: static string)</a></li>
  89. <li><a class="reference" href="#formatValue%2Cstring%2Cstring%2Cstring" title="formatValue(result: var string; value: string; specifier: string)">formatValue(result: var string; value: string; specifier: string)</a></li>
  90. <li><a class="reference" href="#formatValue%2Cstring%2CT%2Cstaticstring" title="formatValue[T: SomeInteger](result: var string; value: T;
  91. specifier: static string)">formatValue[T: SomeInteger](result: var string; value: T;
  92. specifier: static string)</a></li>
  93. <li><a class="reference" href="#formatValue%2Cstring%2CT%2Cstring" title="formatValue[T: SomeInteger](result: var string; value: T; specifier: string)">formatValue[T: SomeInteger](result: var string; value: T; specifier: string)</a></li>
  94. </ul>
  95. <ul class="simple nested-toc-section">parseStandardFormatSpecifier
  96. <li><a class="reference" href="#parseStandardFormatSpecifier%2Cstring%2Cint" title="parseStandardFormatSpecifier(s: string; start = 0; ignoreUnknownSuffix = false): StandardFormatSpecifier">parseStandardFormatSpecifier(s: string; start = 0; ignoreUnknownSuffix = false): StandardFormatSpecifier</a></li>
  97. </ul>
  98. </ul>
  99. </details>
  100. </li>
  101. <li>
  102. <details open>
  103. <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
  104. <ul class="simple simple-toc-section">
  105. <ul class="simple nested-toc-section">&
  106. <li><a class="reference" href="#%26.t" title="`&amp;`(pattern: string{lit}): string">`&amp;`(pattern: string{lit}): string</a></li>
  107. </ul>
  108. <ul class="simple nested-toc-section">fmt
  109. <li><a class="reference" href="#fmt.t%2Cstaticstring" title="fmt(pattern: static string): untyped">fmt(pattern: static string): untyped</a></li>
  110. <li><a class="reference" href="#fmt.t%2Cstaticstring%2Cstaticchar%2Cstaticchar" title="fmt(pattern: static string; openChar: static char; closeChar: static char): string">fmt(pattern: static string; openChar: static char; closeChar: static char): string</a></li>
  111. </ul>
  112. </ul>
  113. </details>
  114. </li>
  115. </ul>
  116. </div>
  117. <div class="nine columns" id="content">
  118. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  119. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  120. <div id="tocRoot"></div>
  121. <p class="module-desc">String <span id="interpolation_1">interpolation</span> / <span id="format_1">format</span> inspired by Python's f-strings.
  122. <h1><a class="toc-backref" id="nimfmt-vsdot-nimamp" href="#nimfmt-vsdot-nimamp"><tt class="docutils literal"><span class="pre"><span class="Identifier">fmt</span></span></tt> vs. <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt></a></h1><p>You can use either <tt class="docutils literal"><span class="pre"><span class="Identifier">fmt</span></span></tt> or the unary <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> operator for formatting. The difference between them is subtle but important.</p>
  123. <p>The <tt class="docutils literal"><span class="pre"><span class="RawData">fmt&quot;{expr}&quot;</span></span></tt> syntax is more aesthetically pleasing, but it hides a small gotcha. The string is a <a class="reference external" href="manual.html#lexical-analysis-generalized-raw-string-literals">generalized raw string literal</a>. This has some surprising effects: </p>
  124. <p><strong class="examples_text">Example:</strong></p>
  125. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  126. <span class="Keyword">let</span> <span class="Identifier">msg</span> <span class="Operator">=</span> <span class="StringLit">&quot;hello&quot;</span>
  127. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{msg}\n&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello</span><span class="EscapeSequence">\\</span><span class="StringLit">n&quot;</span></pre><p>Because the literal is a raw string literal, the <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">n</span></span></tt> is not interpreted as an escape sequence.</p>
  128. <p>There are multiple ways to get around this, including the use of the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> operator: </p>
  129. <p><strong class="examples_text">Example:</strong></p>
  130. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  131. <span class="Keyword">let</span> <span class="Identifier">msg</span> <span class="Operator">=</span> <span class="StringLit">&quot;hello&quot;</span>
  132. <span class="Identifier">assert</span> <span class="Operator">&amp;</span><span class="StringLit">&quot;{msg}</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span>
  133. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{msg}{'\n'}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span>
  134. <span class="Identifier">assert</span> <span class="Identifier">fmt</span><span class="Punctuation">(</span><span class="StringLit">&quot;{msg}</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span>
  135. <span class="Identifier">assert</span> <span class="StringLit">&quot;{msg}</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span></pre>The choice of style is up to you.
  136. <h1><a class="toc-backref" id="formatting-strings" href="#formatting-strings">Formatting strings</a></h1>
  137. <p><strong class="examples_text">Example:</strong></p>
  138. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  139. <span class="Identifier">assert</span> <span class="Operator">&amp;</span><span class="LongStringLit">&quot;&quot;&quot;{&quot;abc&quot;:&gt;4}&quot;&quot;&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; abc&quot;</span>
  140. <span class="Identifier">assert</span> <span class="Operator">&amp;</span><span class="LongStringLit">&quot;&quot;&quot;{&quot;abc&quot;:&lt;4}&quot;&quot;&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;abc &quot;</span></pre>
  141. <h1><a class="toc-backref" id="formatting-floats" href="#formatting-floats">Formatting floats</a></h1>
  142. <p><strong class="examples_text">Example:</strong></p>
  143. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  144. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{-12345:08}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;-0012345&quot;</span>
  145. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{-1:3}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; -1&quot;</span>
  146. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{-1:03}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;-01&quot;</span>
  147. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{16:#X}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;0x10&quot;</span>
  148. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;123.456&quot;</span>
  149. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:&gt;9.3f}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; 123.456&quot;</span>
  150. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:9.3f}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; 123.456&quot;</span>
  151. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:9.4f}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; 123.4560&quot;</span>
  152. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:&gt;9.0f}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; 123.&quot;</span>
  153. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:&lt;9.4f}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;123.4560 &quot;</span>
  154. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:e}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;1.234560e+02&quot;</span>
  155. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:&gt;13e}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; 1.234560e+02&quot;</span>
  156. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456:13e}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot; 1.234560e+02&quot;</span></pre>
  157. <h1><a class="toc-backref" id="expressions" href="#expressions">Expressions</a></h1>
  158. <p><strong class="examples_text">Example:</strong></p>
  159. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  160. <span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="FloatNumber">3.14</span>
  161. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{(if x!=0: 1.0/x else: 0):.5}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;0.31847&quot;</span>
  162. <span class="Identifier">assert</span> <span class="LongStringLit">fmt&quot;&quot;&quot;{(block:
  163. var res: string
  164. for i in 1..15:
  165. res.add (if i mod 15 == 0: &quot;FizzBuzz&quot;
  166. elif i mod 5 == 0: &quot;Buzz&quot;
  167. elif i mod 3 == 0: &quot;Fizz&quot;
  168. else: $i) &amp; &quot; &quot;
  169. res)}&quot;&quot;&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz &quot;</span></pre>
  170. <h1><a class="toc-backref" id="debugging-strings" href="#debugging-strings">Debugging strings</a></h1><p><tt class="docutils literal"><span class="pre"><span class="RawData">fmt&quot;{expr=}&quot;</span></span></tt> expands to <tt class="docutils literal"><span class="pre"><span class="RawData">fmt&quot;expr={expr}&quot;</span></span></tt> namely the text of the expression, an equal sign and the results of evaluated expression. </p>
  171. <p><strong class="examples_text">Example:</strong></p>
  172. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  173. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456=}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;123.456=123.456&quot;</span>
  174. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{123.456=:&gt;9.3f}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;123.456= 123.456&quot;</span>
  175. <span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="StringLit">&quot;hello&quot;</span>
  176. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x=}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x=hello&quot;</span>
  177. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x =}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x =hello&quot;</span>
  178. <span class="Keyword">let</span> <span class="Identifier">y</span> <span class="Operator">=</span> <span class="FloatNumber">3.1415926</span>
  179. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{y=:.2f}&quot;</span> <span class="Operator">==</span> <span class="RawData">fmt&quot;y={y:.2f}&quot;</span>
  180. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{y=}&quot;</span> <span class="Operator">==</span> <span class="RawData">fmt&quot;y={y}&quot;</span>
  181. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{y = : &lt;8}&quot;</span> <span class="Operator">==</span> <span class="RawData">fmt&quot;y = 3.14159 &quot;</span>
  182. <span class="Keyword">proc</span> <span class="Identifier">hello</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">:</span> <span class="Identifier">float</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">int</span> <span class="Operator">=</span> <span class="DecNumber">12</span>
  183. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{hello(x, y) = }&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello(x, y) = 12&quot;</span>
  184. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x.hello(y) = }&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x.hello(y) = 12&quot;</span>
  185. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{hello x, y = }&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello x, y = 12&quot;</span></pre>Note that it is space sensitive:
  186. <p><strong class="examples_text">Example:</strong></p>
  187. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  188. <span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="StringLit">&quot;12&quot;</span>
  189. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x=}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x=12&quot;</span>
  190. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x =:}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x =12&quot;</span>
  191. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x =}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x =12&quot;</span>
  192. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x= :}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x= 12&quot;</span>
  193. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x= }&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x= 12&quot;</span>
  194. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x = :}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x = 12&quot;</span>
  195. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x = }&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x = 12&quot;</span>
  196. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x = :}&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x = 12&quot;</span>
  197. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;{x = }&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;x = 12&quot;</span></pre>
  198. <h1><a class="toc-backref" id="implementation-details" href="#implementation-details">Implementation details</a></h1><p>An expression like <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span><span class="StringLit">&quot;{key} is {value:arg} {{z}}&quot;</span></span></tt> is transformed into:</p>
  199. <p><pre class="listing"><span class="Keyword">var</span> <span class="Identifier">temp</span> <span class="Operator">=</span> <span class="Identifier">newStringOfCap</span><span class="Punctuation">(</span><span class="Identifier">educatedCapGuess</span><span class="Punctuation">)</span>
  200. <span class="Identifier">temp</span><span class="Operator">.</span><span class="Identifier">formatValue</span><span class="Punctuation">(</span><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span>
  201. <span class="Identifier">temp</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="StringLit">&quot; is &quot;</span><span class="Punctuation">)</span>
  202. <span class="Identifier">temp</span><span class="Operator">.</span><span class="Identifier">formatValue</span><span class="Punctuation">(</span><span class="Identifier">value</span><span class="Punctuation">,</span> <span class="Identifier">arg</span><span class="Punctuation">)</span>
  203. <span class="Identifier">temp</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="StringLit">&quot; {z}&quot;</span><span class="Punctuation">)</span>
  204. <span class="Identifier">temp</span></pre></p>
  205. <p>Parts of the string that are enclosed in the curly braces are interpreted as Nim code. To escape a <tt class="docutils literal"><span class="pre"><span class="Punctuation">{</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Punctuation">}</span></span></tt>, double it.</p>
  206. <p>Within a curly expression, however, <tt class="docutils literal"><span class="pre"><span class="Punctuation">{</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Punctuation">}</span></span></tt>, must be escaped with a backslash.</p>
  207. <p>To enable evaluating Nim expressions within curlies, colons inside parentheses do not need to be escaped. </p>
  208. <p><strong class="examples_text">Example:</strong></p>
  209. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strformat</span>
  210. <span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="StringLit">&quot;hello&quot;</span>
  211. <span class="Identifier">assert</span> <span class="LongStringLit">fmt&quot;&quot;&quot;{ &quot;\{(&quot; &amp; x &amp; &quot;)\}&quot; }&quot;&quot;&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;{(hello)}&quot;</span>
  212. <span class="Identifier">assert</span> <span class="LongStringLit">fmt&quot;&quot;&quot;{{({ x })}}&quot;&quot;&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;{(hello)}&quot;</span>
  213. <span class="Identifier">assert</span> <span class="LongStringLit">fmt&quot;&quot;&quot;{ $(\{x:1,&quot;world&quot;:2\}) }&quot;&quot;&quot;</span> <span class="Operator">==</span> <span class="LongStringLit">&quot;&quot;&quot;[(&quot;hello&quot;, 1), (&quot;world&quot;, 2)]&quot;&quot;&quot;</span></pre><p><tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> delegates most of the work to an open overloaded set of <tt class="docutils literal"><span class="pre"><span class="Identifier">formatValue</span></span></tt> procs. The required signature for a type <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt> that supports formatting is usually <tt class="docutils literal"><span class="pre"><span class="Keyword">proc</span> <span class="Identifier">formatValue</span><span class="Punctuation">(</span><span class="Identifier">result</span><span class="Punctuation">:</span> <span class="Keyword">var</span> <span class="Identifier">string</span><span class="Punctuation">;</span> <span class="Identifier">x</span><span class="Punctuation">:</span> <span class="Identifier">T</span><span class="Punctuation">;</span> <span class="Identifier">specifier</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">)</span></span></tt>.</p>
  214. <p>The subexpression after the colon (<tt class="docutils literal"><span class="pre"><span class="Identifier">arg</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span><span class="StringLit">&quot;{key} is {value:arg} {{z}}&quot;</span></span></tt>) is optional. It will be passed as the last argument to <tt class="docutils literal"><span class="pre"><span class="Identifier">formatValue</span></span></tt>. When the colon with the subexpression it is left out, an empty string will be taken instead.</p>
  215. <p>For strings and numeric types the optional argument is a so-called &quot;standard format specifier&quot;.</p>
  216. <h1><a class="toc-backref" id="standard-format-specifiers-for-strings-integers-and-floats" href="#standard-format-specifiers-for-strings-integers-and-floats">Standard format specifiers for strings, integers and floats</a></h1><p>The general form of a standard format specifier is:</p>
  217. <pre>[[fill]align][sign][#][0][minimumwidth][.precision][type]</pre>
  218. <p>The square brackets <tt class="docutils literal"><span class="pre"><span class="Punctuation">[</span><span class="Punctuation">]</span></span></tt> indicate an optional element.</p>
  219. <p>The optional <tt class="docutils literal"><span class="pre"><span class="Identifier">align</span></span></tt> flag can be one of the following:</p>
  220. <dl class="docutils"><dt><tt class="docutils literal"><span class="pre"><span class="Operator">&lt;</span></span></tt></dt>
  221. <dd>Forces the field to be left-aligned within the available space. (This is the default for strings.)</dd>
  222. <dt><tt class="docutils literal"><span class="pre"><span class="Operator">&gt;</span></span></tt></dt>
  223. <dd>Forces the field to be right-aligned within the available space. (This is the default for numbers.)</dd>
  224. <dt><tt class="docutils literal"><span class="pre"><span class="Operator">^</span></span></tt></dt>
  225. <dd>Forces the field to be centered within the available space.</dd>
  226. </dl>
  227. <p>Note that unless a minimum field width is defined, the field width will always be the same size as the data to fill it, so that the alignment option has no meaning in this case.</p>
  228. <p>The optional <tt class="docutils literal"><span class="pre"><span class="Identifier">fill</span></span></tt> character defines the character to be used to pad the field to the minimum width. The fill character, if present, must be followed by an alignment flag.</p>
  229. <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">sign</span></span></tt> option is only valid for numeric types, and can be one of the following:</p>
  230. <table border="1" class="docutils"><tr><th>Sign</th><th>Meaning</th></tr>
  231. <tr><td><tt class="docutils literal"><span class="pre"><span class="Operator">+</span></span></tt></td><td>Indicates that a sign should be used for both positive as well as negative numbers.</td></tr>
  232. <tr><td><tt class="docutils literal"><span class="pre"><span class="Operator">-</span></span></tt></td><td>Indicates that a sign should be used only for negative numbers (this is the default behavior).</td></tr>
  233. <tr><td>(space)</td><td>Indicates that a leading space should be used on positive numbers.</td></tr>
  234. </table><p>If the <tt class="docutils literal"><span class="pre"><span class="Comment">#</span></span></tt> character is present, integers use the 'alternate form' for formatting. This means that binary, octal and hexadecimal output will be prefixed with <tt class="docutils literal"><span class="pre"><span class="BinNumber">0b</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="OctNumber">0o</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="HexNumber">0x</span></span></tt>, respectively.</p>
  235. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">width</span></span></tt> is a decimal integer defining the minimum field width. If not specified, then the field width will be determined by the content.</p>
  236. <p>If the width field is preceded by a zero (<tt class="docutils literal"><span class="pre"><span class="DecNumber">0</span></span></tt>) character, this enables zero-padding.</p>
  237. <p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">precision</span></span></tt> is a decimal number indicating how many digits should be displayed after the decimal point in a floating point conversion. For non-numeric types the field indicates the maximum field size - in other words, how many characters will be used from the field content. The precision is ignored for integer conversions.</p>
  238. <p>Finally, the <tt class="docutils literal"><span class="pre"><span class="Keyword">type</span></span></tt> determines how the data should be presented.</p>
  239. <p>The available integer presentation types are:</p>
  240. <table border="1" class="docutils"><tr><th>Type</th><th>Result</th></tr>
  241. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">b</span></span></tt></td><td>Binary. Outputs the number in base 2.</td></tr>
  242. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">d</span></span></tt></td><td>Decimal Integer. Outputs the number in base 10.</td></tr>
  243. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">o</span></span></tt></td><td>Octal format. Outputs the number in base 8.</td></tr>
  244. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt></td><td>Hex format. Outputs the number in base 16, using lower-case letters for the digits above 9.</td></tr>
  245. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">X</span></span></tt></td><td>Hex format. Outputs the number in base 16, using uppercase letters for the digits above 9.</td></tr>
  246. <tr><td>(None)</td><td>The same as <tt class="docutils literal"><span class="pre"><span class="Identifier">d</span></span></tt>.</td></tr>
  247. </table><p>The available floating point presentation types are:</p>
  248. <table border="1" class="docutils"><tr><th>Type</th><th>Result</th></tr>
  249. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">e</span></span></tt></td><td>Exponent notation. Prints the number in scientific notation using the letter <tt class="docutils literal"><span class="pre"><span class="Identifier">e</span></span></tt> to indicate the exponent.</td></tr>
  250. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt></td><td>Exponent notation. Same as <tt class="docutils literal"><span class="pre"><span class="Identifier">e</span></span></tt> except it converts the number to uppercase.</td></tr>
  251. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt></td><td>Fixed point. Displays the number as a fixed-point number.</td></tr>
  252. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">F</span></span></tt></td><td>Fixed point. Same as <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt> except it converts the number to uppercase.</td></tr>
  253. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">g</span></span></tt></td><td>General format. This prints the number as a fixed-point number, unless the number is too large, in which case it switches to <tt class="docutils literal"><span class="pre"><span class="Identifier">e</span></span></tt> exponent notation.</td></tr>
  254. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">G</span></span></tt></td><td>General format. Same as <tt class="docutils literal"><span class="pre"><span class="Identifier">g</span></span></tt> except it switches to <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> if the number gets to large.</td></tr>
  255. <tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt></td><td>Complex General format. This is only supported for complex numbers, which it prints using the mathematical (RE+IMj) format. The real and imaginary parts are printed using the general format <tt class="docutils literal"><span class="pre"><span class="Identifier">g</span></span></tt> by default, but it is possible to combine this format with one of the other formats (e.g <tt class="docutils literal"><span class="pre"><span class="Identifier">jf</span></span></tt>).</td></tr>
  256. <tr><td>(None)</td><td>Similar to <tt class="docutils literal"><span class="pre"><span class="Identifier">g</span></span></tt>, except that it prints at least one digit after the decimal point.</td></tr>
  257. </table>
  258. <h1><a class="toc-backref" id="limitations" href="#limitations">Limitations</a></h1><p>Because of the well defined order how templates and macros are expanded, strformat cannot expand template arguments:</p>
  259. <p><pre class="listing"><span class="Keyword">template</span> <span class="Identifier">myTemplate</span><span class="Punctuation">(</span><span class="Identifier">arg</span><span class="Punctuation">:</span> <span class="Identifier">untyped</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">untyped</span> <span class="Operator">=</span>
  260. <span class="Identifier">echo</span> <span class="StringLit">&quot;arg is: &quot;</span><span class="Punctuation">,</span> <span class="Identifier">arg</span>
  261. <span class="Identifier">echo</span> <span class="Operator">&amp;</span><span class="StringLit">&quot;--- {arg} ---&quot;</span>
  262. <span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="StringLit">&quot;abc&quot;</span>
  263. <span class="Identifier">myTemplate</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span></pre></p>
  264. <p>First the template <tt class="docutils literal"><span class="pre"><span class="Identifier">myTemplate</span></span></tt> is expanded, where every identifier <tt class="docutils literal"><span class="pre"><span class="Identifier">arg</span></span></tt> is substituted with its argument. The <tt class="docutils literal"><span class="pre"><span class="Identifier">arg</span></span></tt> inside the format string is not seen by this process, because it is part of a quoted string literal. It is not an identifier yet. Then the strformat macro creates the <tt class="docutils literal"><span class="pre"><span class="Identifier">arg</span></span></tt> identifier from the string literal, an identifier that cannot be resolved anymore.</p>
  265. <p>The workaround for this is to bind the template argument to a new local variable.</p>
  266. <p><pre class="listing"><span class="Keyword">template</span> <span class="Identifier">myTemplate</span><span class="Punctuation">(</span><span class="Identifier">arg</span><span class="Punctuation">:</span> <span class="Identifier">untyped</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">untyped</span> <span class="Operator">=</span>
  267. <span class="Keyword">block</span><span class="Punctuation">:</span>
  268. <span class="Keyword">let</span> <span class="Identifier">arg1</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">inject</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span> <span class="Identifier">arg</span>
  269. <span class="Identifier">echo</span> <span class="StringLit">&quot;arg is: &quot;</span><span class="Punctuation">,</span> <span class="Identifier">arg1</span>
  270. <span class="Identifier">echo</span> <span class="Operator">&amp;</span><span class="StringLit">&quot;--- {arg1} ---&quot;</span></pre></p>
  271. <p>The use of <tt class="docutils literal"><span class="pre"><span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">inject</span><span class="Operator">.</span><span class="Punctuation">}</span></span></tt> here is necessary again because of template expansion order and hygienic templates. But since we generally want to keep the hygiene of <tt class="docutils literal"><span class="pre"><span class="Identifier">myTemplate</span></span></tt>, and we do not want <tt class="docutils literal"><span class="pre"><span class="Identifier">arg1</span></span></tt> to be injected into the context where <tt class="docutils literal"><span class="pre"><span class="Identifier">myTemplate</span></span></tt> is expanded, everything is wrapped in a <tt class="docutils literal"><span class="pre"><span class="Keyword">block</span></span></tt>.</p>
  272. <h1><a class="toc-backref" id="future-directions" href="#future-directions">Future directions</a></h1><p>A curly expression with commas in it like <tt class="docutils literal"><span class="pre"><span class="Punctuation">{</span><span class="Identifier">x</span><span class="Punctuation">,</span> <span class="Identifier">argA</span><span class="Punctuation">,</span> <span class="Identifier">argB</span><span class="Punctuation">}</span></span></tt> could be transformed to <tt class="docutils literal"><span class="pre"><span class="Identifier">formatValue</span><span class="Punctuation">(</span><span class="Identifier">result</span><span class="Punctuation">,</span> <span class="Identifier">x</span><span class="Punctuation">,</span> <span class="Identifier">argA</span><span class="Punctuation">,</span> <span class="Identifier">argB</span><span class="Punctuation">)</span></span></tt> in order to support formatters that do not need to parse a custom language within a custom language but instead prefer to use Nim's existing syntax. This would also help with readability, since there is only so much you can cram into single letter DSLs. </p>
  273. </p>
  274. <div class="section" id="6">
  275. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  276. <dl class="item">
  277. <a class="reference external" href="macros.html">macros</a>, <a class="reference external" href="parseutils.html">parseutils</a>, <a class="reference external" href="unicode.html">unicode</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="assertions.html">assertions</a>
  278. </dl>
  279. </div>
  280. <div class="section" id="7">
  281. <h1><a class="toc-backref" href="#7">Types</a></h1>
  282. <dl class="item">
  283. <div id="StandardFormatSpecifier">
  284. <dt><pre><a href="strformat.html#StandardFormatSpecifier"><span class="Identifier">StandardFormatSpecifier</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
  285. <span class="Identifier">fill</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">align</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a> <span class="Comment">## Desired fill and alignment.</span>
  286. <span class="Identifier">sign</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a> <span class="Comment">## Desired sign.</span>
  287. <span class="Identifier">alternateForm</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> <span class="Comment">## Whether to prefix binary, octal and hex numbers</span>
  288. <span class="Comment">## with `0b`, `0o`, `0x`.</span>
  289. <span class="Identifier">padWithZero</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> <span class="Comment">## Whether to pad with zeros rather than spaces.</span>
  290. <span class="Identifier">minimumWidth</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">precision</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Comment">## Desired minimum width and precision.</span>
  291. <span class="Identifier">typ</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a> <span class="Comment">## Type like 'f', 'g' or 'd'.</span>
  292. <span class="Identifier">endPosition</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Comment">## End position in the format specifier after</span>
  293. <span class="Comment">## `parseStandardFormatSpecifier` returned.</span></pre></dt>
  294. <dd>
  295. Type that describes &quot;standard format specifiers&quot;.
  296. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L359" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  297. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L359" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  298. </dd>
  299. </div>
  300. </dl>
  301. </div>
  302. <div class="section" id="12">
  303. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  304. <dl class="item">
  305. <div id="alignString-procs-all">
  306. <div id="alignString,string,int,char,char">
  307. <dt><pre><span class="Keyword">proc</span> <a href="#alignString%2Cstring%2Cint%2Cchar%2Cchar"><span class="Identifier">alignString</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">minimumWidth</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">align</span> <span class="Other">=</span> <span class="CharLit">'\x00'</span><span class="Other">;</span> <span class="Identifier">fill</span> <span class="Other">=</span> <span class="CharLit">' '</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  308. <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>
  309. <dd>
  310. Aligns <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> using the <tt class="docutils literal"><span class="pre"><span class="Identifier">fill</span></span></tt> char. This is only of interest if you want to write a custom <tt class="docutils literal"><span class="pre"><span class="Identifier">format</span></span></tt> proc that should support the standard format specifiers.
  311. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L339" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  312. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L339" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  313. </dd>
  314. </div>
  315. </div>
  316. <div id="formatValue-procs-all">
  317. <div id="formatValue,string,SomeFloat,staticstring">
  318. <dt><pre><span class="Keyword">proc</span> <a href="#formatValue%2Cstring%2CSomeFloat%2Cstaticstring"><span class="Identifier">formatValue</span></a><span class="Other">(</span><span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#SomeFloat"><span class="Identifier">SomeFloat</span></a><span class="Other">;</span> <span class="Identifier">specifier</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">string</span><span class="Other">)</span></pre></dt>
  319. <dd>
  320. Standard format implementation for <tt class="docutils literal"><span class="pre"><span class="Identifier">SomeFloat</span></span></tt>. It makes little sense to call this directly, but it is required to exist by the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> macro.
  321. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L569" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  322. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L569" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  323. </dd>
  324. </div>
  325. <div id="formatValue,string,SomeFloat,string">
  326. <dt><pre><span class="Keyword">proc</span> <a href="#formatValue%2Cstring%2CSomeFloat%2Cstring"><span class="Identifier">formatValue</span></a><span class="Other">(</span><span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#SomeFloat"><span class="Identifier">SomeFloat</span></a><span class="Other">;</span> <span class="Identifier">specifier</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span></pre></dt>
  327. <dd>
  328. Standard format implementation for <tt class="docutils literal"><span class="pre"><span class="Identifier">SomeFloat</span></span></tt>. It makes little sense to call this directly, but it is required to exist by the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> macro.
  329. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L582" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  330. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L582" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  331. </dd>
  332. </div>
  333. <div id="formatValue,string,string,staticstring">
  334. <dt><pre><span class="Keyword">proc</span> <a href="#formatValue%2Cstring%2Cstring%2Cstaticstring"><span class="Identifier">formatValue</span></a><span class="Other">(</span><span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><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 class="Identifier">specifier</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">string</span><span class="Other">)</span></pre></dt>
  335. <dd>
  336. Standard format implementation for <tt class="docutils literal"><span class="pre"><span class="Identifier">string</span></span></tt>. It makes little sense to call this directly, but it is required to exist by the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> macro.
  337. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L595" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  338. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L595" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  339. </dd>
  340. </div>
  341. <div id="formatValue,string,string,string">
  342. <dt><pre><span class="Keyword">proc</span> <a href="#formatValue%2Cstring%2Cstring%2Cstring"><span class="Identifier">formatValue</span></a><span class="Other">(</span><span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><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 class="Identifier">specifier</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.
  343. <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="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="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>
  344. <dd>
  345. Standard format implementation for <tt class="docutils literal"><span class="pre"><span class="Identifier">string</span></span></tt>. It makes little sense to call this directly, but it is required to exist by the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> macro.
  346. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L613" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  347. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L613" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  348. </dd>
  349. </div>
  350. <div id="formatValue,string,T,staticstring">
  351. <dt><pre><span class="Keyword">proc</span> <a href="#formatValue%2Cstring%2CT%2Cstaticstring"><span class="Identifier">formatValue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span>
  352. <span class="Identifier">specifier</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">string</span><span class="Other">)</span></pre></dt>
  353. <dd>
  354. Standard format implementation for <tt class="docutils literal"><span class="pre"><span class="Identifier">SomeInteger</span></span></tt>. It makes little sense to call this directly, but it is required to exist by the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> macro.
  355. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L493" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  356. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L493" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  357. </dd>
  358. </div>
  359. <div id="formatValue,string,T,string">
  360. <dt><pre><span class="Keyword">proc</span> <a href="#formatValue%2Cstring%2CT%2Cstring"><span class="Identifier">formatValue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">specifier</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span></pre></dt>
  361. <dd>
  362. Standard format implementation for <tt class="docutils literal"><span class="pre"><span class="Identifier">SomeInteger</span></span></tt>. It makes little sense to call this directly, but it is required to exist by the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> macro.
  363. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L507" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  364. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L507" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  365. </dd>
  366. </div>
  367. </div>
  368. <div id="parseStandardFormatSpecifier-procs-all">
  369. <div id="parseStandardFormatSpecifier,string,int">
  370. <dt><pre><span class="Keyword">proc</span> <a href="#parseStandardFormatSpecifier%2Cstring%2Cint"><span class="Identifier">parseStandardFormatSpecifier</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span>
  371. <span class="Identifier">ignoreUnknownSuffix</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="strformat.html#StandardFormatSpecifier"><span class="Identifier">StandardFormatSpecifier</span></a> {.
  372. <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="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="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>
  373. <dd>
  374. An exported helper proc that parses the &quot;standard format specifiers&quot;, as specified by the grammar:<pre>[[fill]align][sign][#][0][minimumwidth][.precision][type]</pre>
  375. <p>This is only of interest if you want to write a custom <tt class="docutils literal"><span class="pre"><span class="Identifier">format</span></span></tt> proc that should support the standard format specifiers. If <tt class="docutils literal"><span class="pre"><span class="Identifier">ignoreUnknownSuffix</span></span></tt> is true, an unknown suffix after the <tt class="docutils literal"><span class="pre"><span class="Keyword">type</span></span></tt> field is not an error.</p>
  376. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L432" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  377. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L432" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  378. </dd>
  379. </div>
  380. </div>
  381. </dl>
  382. </div>
  383. <div class="section" id="18">
  384. <h1><a class="toc-backref" href="#18">Templates</a></h1>
  385. <dl class="item">
  386. <div id="&amp;-templates-all">
  387. <div id="&.t">
  388. <dt><pre><span class="Keyword">template</span> <a href="#%26.t"><span class="Identifier">`&amp;`</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">{</span><span class="Identifier">lit</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 class="Identifier">callsite</span>.}</pre></dt>
  389. <dd>
  390. <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span><span class="Identifier">pattern</span></span></tt> is the same as <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span><span class="Operator">.</span><span class="Identifier">fmt</span></span></tt>. For a specification of the <tt class="docutils literal"><span class="pre"><span class="Operator">&amp;</span></span></tt> macro, see the module level documentation.
  391. <p><strong class="examples_text">Example:</strong></p>
  392. <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="DecNumber">7</span>
  393. <span class="Identifier">assert</span> <span class="Operator">&amp;</span><span class="StringLit">&quot;{x}</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;7</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Comment"># regular string literal</span>
  394. <span class="Identifier">assert</span> <span class="Operator">&amp;</span><span class="StringLit">&quot;{x}</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">==</span> <span class="StringLit">&quot;{x}</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span> <span class="Comment"># `fmt` can be used instead</span>
  395. <span class="Identifier">assert</span> <span class="Operator">&amp;</span><span class="StringLit">&quot;{x}</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">!=</span> <span class="RawData">fmt&quot;{x}\n&quot;</span> <span class="Comment"># see `fmt` docs, this would use a raw string literal</span></pre>
  396. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L776" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  397. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L776" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  398. </dd>
  399. </div>
  400. </div>
  401. <div id="fmt-templates-all">
  402. <div id="fmt.t,staticstring">
  403. <dt><pre><span class="Keyword">template</span> <a href="#fmt.t%2Cstaticstring"><span class="Identifier">fmt</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a> {.<span class="Identifier">callsite</span>.}</pre></dt>
  404. <dd>
  405. Alias for <tt class="docutils literal"><span class="pre"><span class="Identifier">fmt</span><span class="Punctuation">(</span><span class="Identifier">pattern</span><span class="Punctuation">,</span> <span class="CharLit">'{'</span><span class="Punctuation">,</span> <span class="CharLit">'}'</span><span class="Punctuation">)</span></span></tt>.
  406. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L772" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  407. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L772" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  408. </dd>
  409. </div>
  410. <div id="fmt.t,staticstring,staticchar,staticchar">
  411. <dt><pre><span class="Keyword">template</span> <a href="#fmt.t%2Cstaticstring%2Cstaticchar%2Cstaticchar"><span class="Identifier">fmt</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">openChar</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">char</span><span class="Other">;</span>
  412. <span class="Identifier">closeChar</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">char</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">callsite</span>.}</pre></dt>
  413. <dd>
  414. Interpolates <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> using symbols in scope.
  415. <p><strong class="examples_text">Example:</strong></p>
  416. <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="DecNumber">7</span>
  417. <span class="Identifier">assert</span> <span class="StringLit">&quot;var is {x * 2}&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span> <span class="Operator">==</span> <span class="StringLit">&quot;var is 14&quot;</span>
  418. <span class="Identifier">assert</span> <span class="StringLit">&quot;var is {{x}}&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span> <span class="Operator">==</span> <span class="StringLit">&quot;var is {x}&quot;</span> <span class="Comment"># escape via doubling</span>
  419. <span class="Keyword">const</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="StringLit">&quot;foo: {x}&quot;</span>
  420. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">fmt</span> <span class="Operator">==</span> <span class="StringLit">&quot;foo: 7&quot;</span> <span class="Comment"># also works with const strings</span>
  421. <span class="Identifier">assert</span> <span class="RawData">fmt&quot;\n&quot;</span> <span class="Operator">==</span> <span class="RawData">r&quot;\n&quot;</span> <span class="Comment"># raw string literal</span>
  422. <span class="Identifier">assert</span> <span class="StringLit">&quot;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span> <span class="Operator">==</span> <span class="StringLit">&quot;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Comment"># regular literal (likewise with `fmt(&quot;\n&quot;)` or `fmt &quot;\n&quot;`)</span></pre>
  423. <p><strong class="examples_text">Example:</strong></p>
  424. <pre class="listing"><span class="Comment"># custom `openChar`, `closeChar`</span>
  425. <span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="DecNumber">7</span>
  426. <span class="Identifier">assert</span> <span class="StringLit">&quot;&lt;x&gt;&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span><span class="Punctuation">(</span><span class="Punctuation">'</span><span class="Operator">&lt;</span><span class="CharLit">', '</span><span class="Operator">&gt;</span><span class="CharLit">') == &quot;7&quot;</span>
  427. <span class="Identifier">assert</span> <span class="StringLit">&quot;&lt;&lt;&lt;x&gt;&gt;&gt;&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span><span class="Punctuation">(</span><span class="Punctuation">'</span><span class="Operator">&lt;</span><span class="CharLit">', '</span><span class="Operator">&gt;</span><span class="CharLit">') == &quot;&lt;7&gt;&quot;</span>
  428. <span class="Identifier">assert</span> <span class="StringLit">&quot;`x`&quot;</span><span class="Operator">.</span><span class="Identifier">fmt</span><span class="Punctuation">(</span><span class="Punctuation">'</span><span class="Punctuation">`</span><span class="Punctuation">'</span><span class="Punctuation">,</span> <span class="CharLit">'`'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;7&quot;</span></pre>
  429. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/strformat.nim#L753" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  430. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/strformat.nim#L753" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  431. </dd>
  432. </div>
  433. </div>
  434. </dl>
  435. </div>
  436. </div>
  437. </div>
  438. <div class="twelve-columns footer">
  439. <span class="nim-sprite"></span>
  440. <br>
  441. <small style="color: var(--hint);">Made with Nim. Generated: 2025-04-03 14:18:37 UTC</small>
  442. </div>
  443. </div>
  444. </div>
  445. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  446. </body>
  447. </html>