1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306 |
- <?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/parseutils</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/parseutils</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>
- <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="#InterpolatedKind" title="InterpolatedKind = enum
- ikStr, ## ``str`` part of the interpolated string
- ikDollar, ## escaped ``$`` part of the interpolated string
- ikVar, ## ``var`` part of the interpolated string
- ikExpr ## ``expr`` part of the interpolated string">InterpolatedKind</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">captureBetween
- <li><a class="reference" href="#captureBetween%2CopenArray%5Bchar%5D%2Cchar%2Cchar" title="captureBetween(s: openArray[char]; first: char; second = '\x00'): string">captureBetween(s: openArray[char]; first: char; second = '\x00'): string</a></li>
- <li><a class="reference" href="#captureBetween%2Cstring%2Cchar%2Cchar%2Cint" title="captureBetween(s: string; first: char; second = '\x00'; start = 0): string">captureBetween(s: string; first: char; second = '\x00'; start = 0): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseBiggestFloat
- <li><a class="reference" href="#parseBiggestFloat%2CopenArray%5Bchar%5D%2CBiggestFloat" title="parseBiggestFloat(s: openArray[char]; number: var BiggestFloat): int">parseBiggestFloat(s: openArray[char]; number: var BiggestFloat): int</a></li>
- <li><a class="reference" href="#parseBiggestFloat%2Cstring%2CBiggestFloat%2Cint" title="parseBiggestFloat(s: string; number: var BiggestFloat; start = 0): int">parseBiggestFloat(s: string; number: var BiggestFloat; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseBiggestInt
- <li><a class="reference" href="#parseBiggestInt%2CopenArray%5Bchar%5D%2CBiggestInt" title="parseBiggestInt(s: openArray[char]; number: var BiggestInt): int">parseBiggestInt(s: openArray[char]; number: var BiggestInt): int</a></li>
- <li><a class="reference" href="#parseBiggestInt%2Cstring%2CBiggestInt%2Cint" title="parseBiggestInt(s: string; number: var BiggestInt; start = 0): int">parseBiggestInt(s: string; number: var BiggestInt; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseBiggestUInt
- <li><a class="reference" href="#parseBiggestUInt%2CopenArray%5Bchar%5D%2CBiggestUInt" title="parseBiggestUInt(s: openArray[char]; number: var BiggestUInt): int">parseBiggestUInt(s: openArray[char]; number: var BiggestUInt): int</a></li>
- <li><a class="reference" href="#parseBiggestUInt%2Cstring%2CBiggestUInt%2Cint" title="parseBiggestUInt(s: string; number: var BiggestUInt; start = 0): int">parseBiggestUInt(s: string; number: var BiggestUInt; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseBin
- <li><a class="reference" href="#parseBin%2CopenArray%5Bchar%5D%2CT%2Cint" title="parseBin[T: SomeInteger](s: openArray[char]; number: var T; maxLen = 0): int">parseBin[T: SomeInteger](s: openArray[char]; number: var T; maxLen = 0): int</a></li>
- <li><a class="reference" href="#parseBin%2Cstring%2CT%2Cint%2Cint" title="parseBin[T: SomeInteger](s: string; number: var T; start = 0; maxLen = 0): int">parseBin[T: SomeInteger](s: string; number: var T; start = 0; maxLen = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseChar
- <li><a class="reference" href="#parseChar%2CopenArray%5Bchar%5D%2Cchar" title="parseChar(s: openArray[char]; c: var char): int">parseChar(s: openArray[char]; c: var char): int</a></li>
- <li><a class="reference" href="#parseChar%2Cstring%2Cchar%2Cint" title="parseChar(s: string; c: var char; start = 0): int">parseChar(s: string; c: var char; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseFloat
- <li><a class="reference" href="#parseFloat%2CopenArray%5Bchar%5D%2Cfloat" title="parseFloat(s: openArray[char]; number: var float): int">parseFloat(s: openArray[char]; number: var float): int</a></li>
- <li><a class="reference" href="#parseFloat%2Cstring%2Cfloat%2Cint" title="parseFloat(s: string; number: var float; start = 0): int">parseFloat(s: string; number: var float; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseHex
- <li><a class="reference" href="#parseHex%2CopenArray%5Bchar%5D%2CT%2Cint" title="parseHex[T: SomeInteger](s: openArray[char]; number: var T; maxLen = 0): int">parseHex[T: SomeInteger](s: openArray[char]; number: var T; maxLen = 0): int</a></li>
- <li><a class="reference" href="#parseHex%2Cstring%2CT%2Cint%2Cint" title="parseHex[T: SomeInteger](s: string; number: var T; start = 0; maxLen = 0): int">parseHex[T: SomeInteger](s: string; number: var T; start = 0; maxLen = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseIdent
- <li><a class="reference" href="#parseIdent%2CopenArray%5Bchar%5D" title="parseIdent(s: openArray[char]): string">parseIdent(s: openArray[char]): string</a></li>
- <li><a class="reference" href="#parseIdent%2CopenArray%5Bchar%5D%2Cstring" title="parseIdent(s: openArray[char]; ident: var string): int">parseIdent(s: openArray[char]; ident: var string): int</a></li>
- <li><a class="reference" href="#parseIdent%2Cstring%2Cstring%2Cint" title="parseIdent(s: string; ident: var string; start = 0): int">parseIdent(s: string; ident: var string; start = 0): int</a></li>
- <li><a class="reference" href="#parseIdent%2Cstring%2Cint" title="parseIdent(s: string; start = 0): string">parseIdent(s: string; start = 0): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseInt
- <li><a class="reference" href="#parseInt%2CopenArray%5Bchar%5D%2Cint" title="parseInt(s: openArray[char]; number: var int): int">parseInt(s: openArray[char]; number: var int): int</a></li>
- <li><a class="reference" href="#parseInt%2Cstring%2Cint%2Cint" title="parseInt(s: string; number: var int; start = 0): int">parseInt(s: string; number: var int; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseOct
- <li><a class="reference" href="#parseOct%2CopenArray%5Bchar%5D%2CT%2Cint" title="parseOct[T: SomeInteger](s: openArray[char]; number: var T; maxLen = 0): int">parseOct[T: SomeInteger](s: openArray[char]; number: var T; maxLen = 0): int</a></li>
- <li><a class="reference" href="#parseOct%2Cstring%2CT%2Cint%2Cint" title="parseOct[T: SomeInteger](s: string; number: var T; start = 0; maxLen = 0): int">parseOct[T: SomeInteger](s: string; number: var T; start = 0; maxLen = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseSaturatedNatural
- <li><a class="reference" href="#parseSaturatedNatural%2CopenArray%5Bchar%5D%2Cint" title="parseSaturatedNatural(s: openArray[char]; b: var int): int">parseSaturatedNatural(s: openArray[char]; b: var int): int</a></li>
- <li><a class="reference" href="#parseSaturatedNatural%2Cstring%2Cint%2Cint" title="parseSaturatedNatural(s: string; b: var int; start = 0): int">parseSaturatedNatural(s: string; b: var int; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseSize
- <li><a class="reference" href="#parseSize%2CopenArray%5Bchar%5D%2Cint64" title="parseSize(s: openArray[char]; size: var int64; alwaysBin = false): int">parseSize(s: openArray[char]; size: var int64; alwaysBin = false): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseUInt
- <li><a class="reference" href="#parseUInt%2CopenArray%5Bchar%5D%2Cuint" title="parseUInt(s: openArray[char]; number: var uint): int">parseUInt(s: openArray[char]; number: var uint): int</a></li>
- <li><a class="reference" href="#parseUInt%2Cstring%2Cuint%2Cint" title="parseUInt(s: string; number: var uint; start = 0): int">parseUInt(s: string; number: var uint; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseUntil
- <li><a class="reference" href="#parseUntil%2CopenArray%5Bchar%5D%2Cstring%2Cchar" title="parseUntil(s: openArray[char]; token: var string; until: char): int">parseUntil(s: openArray[char]; token: var string; until: char): int</a></li>
- <li><a class="reference" href="#parseUntil%2CopenArray%5Bchar%5D%2Cstring%2Cset%5Bchar%5D" title="parseUntil(s: openArray[char]; token: var string; until: set[char]): int">parseUntil(s: openArray[char]; token: var string; until: set[char]): int</a></li>
- <li><a class="reference" href="#parseUntil%2CopenArray%5Bchar%5D%2Cstring%2Cstring" title="parseUntil(s: openArray[char]; token: var string; until: string): int">parseUntil(s: openArray[char]; token: var string; until: string): int</a></li>
- <li><a class="reference" href="#parseUntil%2Cstring%2Cstring%2Cchar%2Cint" title="parseUntil(s: string; token: var string; until: char; start = 0): int">parseUntil(s: string; token: var string; until: char; start = 0): int</a></li>
- <li><a class="reference" href="#parseUntil%2Cstring%2Cstring%2Cset%5Bchar%5D%2Cint" title="parseUntil(s: string; token: var string; until: set[char]; start = 0): int">parseUntil(s: string; token: var string; until: set[char]; start = 0): int</a></li>
- <li><a class="reference" href="#parseUntil%2Cstring%2Cstring%2Cstring%2Cint" title="parseUntil(s: string; token: var string; until: string; start = 0): int">parseUntil(s: string; token: var string; until: string; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseWhile
- <li><a class="reference" href="#parseWhile%2CopenArray%5Bchar%5D%2Cstring%2Cset%5Bchar%5D" title="parseWhile(s: openArray[char]; token: var string; validChars: set[char]): int">parseWhile(s: openArray[char]; token: var string; validChars: set[char]): int</a></li>
- <li><a class="reference" href="#parseWhile%2Cstring%2Cstring%2Cset%5Bchar%5D%2Cint" title="parseWhile(s: string; token: var string; validChars: set[char]; start = 0): int">parseWhile(s: string; token: var string; validChars: set[char]; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">skip
- <li><a class="reference" href="#skip%2CopenArray%5Bchar%5D%2CopenArray%5Bchar%5D" title="skip(s, token: openArray[char]): int">skip(s, token: openArray[char]): int</a></li>
- <li><a class="reference" href="#skip%2Cstring%2Cstring%2Cint" title="skip(s, token: string; start = 0): int">skip(s, token: string; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">skipIgnoreCase
- <li><a class="reference" href="#skipIgnoreCase%2CopenArray%5Bchar%5D%2CopenArray%5Bchar%5D" title="skipIgnoreCase(s, token: openArray[char]): int">skipIgnoreCase(s, token: openArray[char]): int</a></li>
- <li><a class="reference" href="#skipIgnoreCase%2Cstring%2Cstring%2Cint" title="skipIgnoreCase(s, token: string; start = 0): int">skipIgnoreCase(s, token: string; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">skipUntil
- <li><a class="reference" href="#skipUntil%2CopenArray%5Bchar%5D%2Cchar" title="skipUntil(s: openArray[char]; until: char): int">skipUntil(s: openArray[char]; until: char): int</a></li>
- <li><a class="reference" href="#skipUntil%2CopenArray%5Bchar%5D%2Cset%5Bchar%5D" title="skipUntil(s: openArray[char]; until: set[char]): int">skipUntil(s: openArray[char]; until: set[char]): int</a></li>
- <li><a class="reference" href="#skipUntil%2Cstring%2Cchar%2Cint" title="skipUntil(s: string; until: char; start = 0): int">skipUntil(s: string; until: char; start = 0): int</a></li>
- <li><a class="reference" href="#skipUntil%2Cstring%2Cset%5Bchar%5D%2Cint" title="skipUntil(s: string; until: set[char]; start = 0): int">skipUntil(s: string; until: set[char]; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">skipWhile
- <li><a class="reference" href="#skipWhile%2CopenArray%5Bchar%5D%2Cset%5Bchar%5D" title="skipWhile(s: openArray[char]; toSkip: set[char]): int">skipWhile(s: openArray[char]; toSkip: set[char]): int</a></li>
- <li><a class="reference" href="#skipWhile%2Cstring%2Cset%5Bchar%5D%2Cint" title="skipWhile(s: string; toSkip: set[char]; start = 0): int">skipWhile(s: string; toSkip: set[char]; start = 0): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">skipWhitespace
- <li><a class="reference" href="#skipWhitespace%2CopenArray%5Bchar%5D" title="skipWhitespace(s: openArray[char]): int">skipWhitespace(s: openArray[char]): int</a></li>
- <li><a class="reference" href="#skipWhitespace%2Cstring%2Cint" title="skipWhitespace(s: string; start = 0): int">skipWhitespace(s: string; start = 0): int</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">interpolatedFragments
- <li><a class="reference" href="#interpolatedFragments.i%2CopenArray%5Bchar%5D" title="interpolatedFragments(s: openArray[char]): tuple[kind: InterpolatedKind,
- value: string]">interpolatedFragments(s: openArray[char]): tuple[kind: InterpolatedKind,
- value: string]</a></li>
- <li><a class="reference" href="#interpolatedFragments.i%2Cstring" title="interpolatedFragments(s: string): tuple[kind: InterpolatedKind, value: string]">interpolatedFragments(s: string): tuple[kind: InterpolatedKind, value: 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/parseutils.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <p class="module-desc"><p>This module contains helpers for parsing tokens, numbers, integers, floats, identifiers, etc.</p>
- <p>To unpack raw bytes look at the <a class="reference external" href="streams.html">streams</a> module.</p>
- <p><pre class="listing"><span class="Keyword">let</span> <span class="Identifier">logs</span> <span class="Operator">=</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">"2019-01-10: OK_"</span><span class="Punctuation">,</span> <span class="StringLit">"2019-01-11: FAIL_"</span><span class="Punctuation">,</span> <span class="StringLit">"2019-01: aaaa"</span><span class="Punctuation">]</span>
- <span class="Keyword">var</span> <span class="Identifier">outp</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span>
- <span class="Keyword">for</span> <span class="Identifier">log</span> <span class="Keyword">in</span> <span class="Identifier">logs</span><span class="Punctuation">:</span>
- <span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Keyword">if</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="Identifier">log</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="CharLit">':'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">10</span><span class="Punctuation">:</span> <span class="Comment"># YYYY-MM-DD == 10</span>
- <span class="Identifier">outp</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">res</span> <span class="Operator">&</span> <span class="StringLit">" - "</span> <span class="Operator">&</span> <span class="Identifier">captureBetween</span><span class="Punctuation">(</span><span class="Identifier">log</span><span class="Punctuation">,</span> <span class="CharLit">' '</span><span class="Punctuation">,</span> <span class="CharLit">'_'</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">outp</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">"2019-01-10 - OK"</span><span class="Punctuation">,</span> <span class="StringLit">"2019-01-11 - FAIL"</span><span class="Punctuation">]</span></pre></p>
- <p><pre class="listing"><span class="Keyword">from</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strutils</span> <span class="Keyword">import</span> <span class="Identifier">Digits</span><span class="Punctuation">,</span> <span class="Identifier">parseInt</span>
- <span class="Keyword">let</span>
- <span class="Identifier">input1</span> <span class="Operator">=</span> <span class="StringLit">"2019 school start"</span>
- <span class="Identifier">input2</span> <span class="Operator">=</span> <span class="StringLit">"3 years back"</span>
- <span class="Identifier">startYear</span> <span class="Operator">=</span> <span class="Identifier">input1</span><span class="Punctuation">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="Identifier">input1</span><span class="Punctuation">,</span> <span class="Identifier">Digits</span><span class="Punctuation">)</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Comment"># 2019</span>
- <span class="Identifier">yearsBack</span> <span class="Operator">=</span> <span class="Identifier">input2</span><span class="Punctuation">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="Identifier">input2</span><span class="Punctuation">,</span> <span class="Identifier">Digits</span><span class="Punctuation">)</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Comment"># 3</span>
- <span class="Identifier">examYear</span> <span class="Operator">=</span> <span class="Identifier">parseInt</span><span class="Punctuation">(</span><span class="Identifier">startYear</span><span class="Punctuation">)</span> <span class="Operator">+</span> <span class="Identifier">parseInt</span><span class="Punctuation">(</span><span class="Identifier">yearsBack</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"Examination is in "</span> <span class="Operator">&</span> <span class="Operator">$</span><span class="Identifier">examYear</span> <span class="Operator">==</span> <span class="StringLit">"Examination is in 2022"</span></pre></p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="strutils.html">strutils module</a> for combined and identical parsing proc's</li>
- <li><a class="reference external" href="json.html">json module</a> for a JSON parser</li>
- <li><a class="reference external" href="parsecfg.html">parsecfg module</a> for a configuration file parser</li>
- <li><a class="reference external" href="parsecsv.html">parsecsv module</a> for a simple CSV (comma separated value) parser</li>
- <li><a class="reference external" href="parseopt.html">parseopt module</a> for a command line parser</li>
- <li><a class="reference external" href="parsexml.html">parsexml module</a> for a XML / HTML parser</li>
- <li><a class="reference external" href="lib.html#pure-libraries-parsers">other parsers</a> for other parsers</li>
- </ul>
- </p>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="InterpolatedKind">
- <dt><pre><a href="parseutils.html#InterpolatedKind"><span class="Identifier">InterpolatedKind</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">ikStr</span><span class="Other">,</span> <span class="Comment">## ``str`` part of the interpolated string</span>
- <span class="Identifier">ikDollar</span><span class="Other">,</span> <span class="Comment">## escaped ``$`` part of the interpolated string</span>
- <span class="Identifier">ikVar</span><span class="Other">,</span> <span class="Comment">## ``var`` part of the interpolated string</span>
- <span class="Identifier">ikExpr</span> <span class="Comment">## ``expr`` part of the interpolated string</span></pre></dt>
- <dd>
-
- Describes for <tt class="docutils literal"><span class="pre"><span class="Identifier">interpolatedFragments</span></span></tt> which part of the interpolated string is yielded; for example in "str$$$var${expr}"
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L676" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L676" 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="captureBetween-procs-all">
- <div id="captureBetween,openArray[char],char,char">
- <dt><pre><span class="Keyword">proc</span> <a href="#captureBetween%2CopenArray%5Bchar%5D%2Cchar%2Cchar"><span class="Identifier">captureBetween</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">first</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">;</span> <span class="Identifier">second</span> <span class="Other">=</span> <span class="CharLit">'\x00'</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>
-
- Finds the first occurrence of <tt class="docutils literal"><span class="pre">first</span></tt>, then returns everything from there up to <tt class="docutils literal"><span class="pre">second</span></tt> (if <tt class="docutils literal"><span class="pre">second</span></tt> is '0', then <tt class="docutils literal"><span class="pre">first</span></tt> is used).
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">captureBetween</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'e'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"llo World"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">captureBetween</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'e'</span><span class="Punctuation">,</span> <span class="CharLit">'r'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"llo Wo"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">captureBetween</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Operator">.</span><span class="Identifier">toOpenArray</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="StringLit">"Hello World"</span><span class="Operator">.</span><span class="Identifier">high</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="CharLit">'l'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"d"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L418" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L418" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="captureBetween,string,char,char,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#captureBetween%2Cstring%2Cchar%2Cchar%2Cint"><span class="Identifier">captureBetween</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">first</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">;</span> <span class="Identifier">second</span> <span class="Other">=</span> <span class="CharLit">'\x00'</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</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>
-
- Finds the first occurrence of <tt class="docutils literal"><span class="pre">first</span></tt>, then returns everything from there up to <tt class="docutils literal"><span class="pre">second</span></tt> (if <tt class="docutils literal"><span class="pre">second</span></tt> is '0', then <tt class="docutils literal"><span class="pre">first</span></tt> is used).
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">captureBetween</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'e'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"llo World"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">captureBetween</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'e'</span><span class="Punctuation">,</span> <span class="CharLit">'r'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"llo Wo"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">captureBetween</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'l'</span><span class="Punctuation">,</span> <span class="Identifier">start</span> <span class="Operator">=</span> <span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"d"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L994" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L994" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseBiggestFloat-procs-all">
- <div id="parseBiggestFloat,openArray[char],BiggestFloat">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBiggestFloat%2CopenArray%5Bchar%5D%2CBiggestFloat"><span class="Identifier">parseBiggestFloat</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="ctypes.html#BiggestFloat"><span class="Identifier">BiggestFloat</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"ParseBiggestFloat"</span><span class="Other">,</span> <span class="Identifier">importc</span><span class="Other">:</span> <span class="StringLit">"nimParseBiggestFloat"</span><span class="Other">,</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>
-
- Parses a float and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if a parsing error occurred.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L586" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L586" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseBiggestFloat,string,BiggestFloat,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBiggestFloat%2Cstring%2CBiggestFloat%2Cint"><span class="Identifier">parseBiggestFloat</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">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="ctypes.html#BiggestFloat"><span class="Identifier">BiggestFloat</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <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>
-
- Parses a float starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt> and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if a parsing error occurred.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1067" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1067" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseBiggestInt-procs-all">
- <div id="parseBiggestInt,openArray[char],BiggestInt">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBiggestInt%2CopenArray%5Bchar%5D%2CBiggestInt"><span class="Identifier">parseBiggestInt</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="ctypes.html#BiggestInt"><span class="Identifier">BiggestInt</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">"npuParseBiggestInt"</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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an integer and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if there is no integer. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">BiggestInt</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestInt</span><span class="Punctuation">(</span><span class="StringLit">"9223372036854775807"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">19</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">9223372036854775807</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestInt</span><span class="Punctuation">(</span><span class="StringLit">"-2024_05_09"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">20240509</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L466" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L466" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseBiggestInt,string,BiggestInt,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBiggestInt%2Cstring%2CBiggestInt%2Cint"><span class="Identifier">parseBiggestInt</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">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="ctypes.html#BiggestInt"><span class="Identifier">BiggestInt</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an integer starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt> and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if there is no integer. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">BiggestInt</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestInt</span><span class="Punctuation">(</span><span class="StringLit">"9223372036854775807"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">19</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">9223372036854775807</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestInt</span><span class="Punctuation">(</span><span class="StringLit">"-2024_05_09"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">20240509</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestInt</span><span class="Punctuation">(</span><span class="StringLit">"-2024_05_02"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">502</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1003" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1003" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseBiggestUInt-procs-all">
- <div id="parseBiggestUInt,openArray[char],BiggestUInt">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBiggestUInt%2CopenArray%5Bchar%5D%2CBiggestUInt"><span class="Identifier">parseBiggestUInt</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="ctypes.html#BiggestUInt"><span class="Identifier">BiggestUInt</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">"npuParseBiggestUInt"</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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an unsigned integer and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">BiggestUInt</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestUInt</span><span class="Punctuation">(</span><span class="StringLit">"12"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">12</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestUInt</span><span class="Punctuation">(</span><span class="StringLit">"1111111111111111111"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">19</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">1111111111111111111'</span><span class="Identifier">u64</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L549" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L549" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseBiggestUInt,string,BiggestUInt,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBiggestUInt%2Cstring%2CBiggestUInt%2Cint"><span class="Identifier">parseBiggestUInt</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">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="ctypes.html#BiggestUInt"><span class="Identifier">BiggestUInt</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an unsigned integer starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt> and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">BiggestUInt</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestUInt</span><span class="Punctuation">(</span><span class="StringLit">"12"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">12</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBiggestUInt</span><span class="Punctuation">(</span><span class="StringLit">"1111111111111111111"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">19</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">1111111111111111111'</span><span class="Identifier">u64</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1043" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1043" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseBin-procs-all">
- <div id="parseBin,openArray[char],T,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBin%2CopenArray%5Bchar%5D%2CT%2Cint"><span class="Identifier">parseBin</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">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">maxLen</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span class="Identifier">noSideEffect</span>.}</pre></dt>
- <dd>
-
- <p>Parses a binary number and stores its value in <tt class="docutils literal"><span class="pre">number</span></tt>.</p>
- <p>Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre">number</span></tt> is not changed.</p>
- <p>If <tt class="docutils literal"><span class="pre">maxLen == 0</span></tt>, the parsing continues until the first non-bin character or to the end of the string. Otherwise, no more than <tt class="docutils literal"><span class="pre">maxLen</span></tt> characters are parsed starting from the <tt class="docutils literal"><span class="pre">start</span></tt> position.</p>
- <p>It does not check for overflow. If the value represented by the string is too big to fit into <tt class="docutils literal"><span class="pre">number</span></tt>, only the value of last fitting characters will be stored in <tt class="docutils literal"><span class="pre">number</span></tt> without producing an error.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">num</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">29</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num</span> <span class="Operator">==</span> <span class="DecNumber">5138925</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"3"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Keyword">var</span> <span class="Identifier">num8</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0b_0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">32</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="BinNumber">0b1110_1101'i8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0b_0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">9</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">9</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="BinNumber">0b0100_1110'i8</span>
- <span class="Keyword">var</span> <span class="Identifier">num8u</span><span class="Punctuation">:</span> <span class="Identifier">uint8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0b_0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num8u</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">32</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8u</span> <span class="Operator">==</span> <span class="DecNumber">237</span>
- <span class="Keyword">var</span> <span class="Identifier">num64</span><span class="Punctuation">:</span> <span class="Identifier">int64</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0100111001101001111011010100111001101001"</span><span class="Punctuation">,</span> <span class="Identifier">num64</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">40</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num64</span> <span class="Operator">==</span> <span class="DecNumber">336784608873</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L63" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L63" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseBin,string,T,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseBin%2Cstring%2CT%2Cint%2Cint"><span class="Identifier">parseBin</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">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">maxLen</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span class="Identifier">noSideEffect</span>.}</pre></dt>
- <dd>
-
- <p>Parses a binary number and stores its value in <tt class="docutils literal"><span class="pre">number</span></tt>.</p>
- <p>Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre">number</span></tt> is not changed.</p>
- <p>If <tt class="docutils literal"><span class="pre">maxLen == 0</span></tt>, the parsing continues until the first non-bin character or to the end of the string. Otherwise, no more than <tt class="docutils literal"><span class="pre">maxLen</span></tt> characters are parsed starting from the <tt class="docutils literal"><span class="pre">start</span></tt> position.</p>
- <p>It does not check for overflow. If the value represented by the string is too big to fit into <tt class="docutils literal"><span class="pre">number</span></tt>, only the value of last fitting characters will be stored in <tt class="docutils literal"><span class="pre">number</span></tt> without producing an error.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">num</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">29</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num</span> <span class="Operator">==</span> <span class="DecNumber">5138925</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"3"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Keyword">var</span> <span class="Identifier">num8</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0b_0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">32</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="BinNumber">0b1110_1101'i8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0b_0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">9</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">9</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="BinNumber">0b0100_1110'i8</span>
- <span class="Keyword">var</span> <span class="Identifier">num8u</span><span class="Punctuation">:</span> <span class="Identifier">uint8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0b_0100_1110_0110_1001_1110_1101"</span><span class="Punctuation">,</span> <span class="Identifier">num8u</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">32</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8u</span> <span class="Operator">==</span> <span class="DecNumber">237</span>
- <span class="Keyword">var</span> <span class="Identifier">num64</span><span class="Punctuation">:</span> <span class="Identifier">int64</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseBin</span><span class="Punctuation">(</span><span class="StringLit">"0100111001101001111011010100111001101001"</span><span class="Punctuation">,</span> <span class="Identifier">num64</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">40</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num64</span> <span class="Operator">==</span> <span class="DecNumber">336784608873</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L747" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L747" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseChar-procs-all">
- <div id="parseChar,openArray[char],char">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseChar%2CopenArray%5Bchar%5D%2Cchar"><span class="Identifier">parseChar</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">c</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#char"><span class="Identifier">char</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">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>
-
- Parses a single character, stores it in <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt> and returns 1. In case of error (if start >= s.len) it returns 0 and the value of <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt> is unchanged.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">c</span><span class="Punctuation">:</span> <span class="Identifier">char</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"nim"</span><span class="Operator">.</span><span class="Identifier">parseChar</span><span class="Punctuation">(</span><span class="Identifier">c</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="CharLit">'\0'</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"nim"</span><span class="Operator">.</span><span class="Identifier">parseChar</span><span class="Punctuation">(</span><span class="Identifier">c</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="CharLit">'n'</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L251" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L251" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseChar,string,char,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseChar%2Cstring%2Cchar%2Cint"><span class="Identifier">parseChar</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">c</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><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">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>
-
- Parses a single character, stores it in <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt> and returns 1. In case of error (if start >= s.len) it returns 0 and the value of <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt> is unchanged.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">c</span><span class="Punctuation">:</span> <span class="Identifier">char</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"nim"</span><span class="Operator">.</span><span class="Identifier">parseChar</span><span class="Punctuation">(</span><span class="Identifier">c</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="CharLit">'\0'</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"nim"</span><span class="Operator">.</span><span class="Identifier">parseChar</span><span class="Punctuation">(</span><span class="Identifier">c</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="CharLit">'n'</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L868" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L868" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseFloat-procs-all">
- <div id="parseFloat,openArray[char],float">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseFloat%2CopenArray%5Bchar%5D%2Cfloat"><span class="Identifier">parseFloat</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#float"><span class="Identifier">float</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">"npuParseFloat"</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>
-
- Parses a float and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if there occurred a parsing error.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">float</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseFloat</span><span class="Punctuation">(</span><span class="StringLit">"32"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="FloatNumber">32.0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseFloat</span><span class="Punctuation">(</span><span class="StringLit">"32.57"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="FloatNumber">32.57</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseFloat</span><span class="Punctuation">(</span><span class="StringLit">"32.57"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="FloatNumber">57.00</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L592" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L592" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseFloat,string,float,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseFloat%2Cstring%2Cfloat%2Cint"><span class="Identifier">parseFloat</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">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#float"><span class="Identifier">float</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<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>
-
- Parses a float starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt> and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if there occurred a parsing error.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">float</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseFloat</span><span class="Punctuation">(</span><span class="StringLit">"32"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="FloatNumber">32.0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseFloat</span><span class="Punctuation">(</span><span class="StringLit">"32.57"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="FloatNumber">32.57</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseFloat</span><span class="Punctuation">(</span><span class="StringLit">"32.57"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="FloatNumber">57.00</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1073" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1073" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseHex-procs-all">
- <div id="parseHex,openArray[char],T,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseHex%2CopenArray%5Bchar%5D%2CT%2Cint"><span class="Identifier">parseHex</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">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">maxLen</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span class="Identifier">noSideEffect</span>.}</pre></dt>
- <dd>
-
- <p>Parses a hexadecimal number and stores its value in <tt class="docutils literal"><span class="pre">number</span></tt>.</p>
- <p>Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre">number</span></tt> is not changed.</p>
- <p>If <tt class="docutils literal"><span class="pre">maxLen == 0</span></tt>, the parsing continues until the first non-hex character or to the end of the string. Otherwise, no more than <tt class="docutils literal"><span class="pre">maxLen</span></tt> characters are parsed starting from the <tt class="docutils literal"><span class="pre">start</span></tt> position.</p>
- <p>It does not check for overflow. If the value represented by the string is too big to fit into <tt class="docutils literal"><span class="pre">number</span></tt>, only the value of last fitting characters will be stored in <tt class="docutils literal"><span class="pre">number</span></tt> without producing an error.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">num</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num</span> <span class="Operator">==</span> <span class="DecNumber">5138925</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"X"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"#ABC"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Keyword">var</span> <span class="Identifier">num8</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"0x_4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="HexNumber">0xED'i8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"0x_4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="HexNumber">0x4E'i8</span>
- <span class="Keyword">var</span> <span class="Identifier">num8u</span><span class="Punctuation">:</span> <span class="Identifier">uint8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"0x_4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num8u</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8u</span> <span class="Operator">==</span> <span class="DecNumber">237</span>
- <span class="Keyword">var</span> <span class="Identifier">num64</span><span class="Punctuation">:</span> <span class="Identifier">int64</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"4E69ED4E69ED"</span><span class="Punctuation">,</span> <span class="Identifier">num64</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">12</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num64</span> <span class="Operator">==</span> <span class="DecNumber">86216859871725</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L159" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L159" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseHex,string,T,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseHex%2Cstring%2CT%2Cint%2Cint"><span class="Identifier">parseHex</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">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">maxLen</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span class="Identifier">noSideEffect</span>.}</pre></dt>
- <dd>
-
- <p>Parses a hexadecimal number and stores its value in <tt class="docutils literal"><span class="pre">number</span></tt>.</p>
- <p>Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre">number</span></tt> is not changed.</p>
- <p>If <tt class="docutils literal"><span class="pre">maxLen == 0</span></tt>, the parsing continues until the first non-hex character or to the end of the string. Otherwise, no more than <tt class="docutils literal"><span class="pre">maxLen</span></tt> characters are parsed starting from the <tt class="docutils literal"><span class="pre">start</span></tt> position.</p>
- <p>It does not check for overflow. If the value represented by the string is too big to fit into <tt class="docutils literal"><span class="pre">number</span></tt>, only the value of last fitting characters will be stored in <tt class="docutils literal"><span class="pre">number</span></tt> without producing an error.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">num</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num</span> <span class="Operator">==</span> <span class="DecNumber">5138925</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"X"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"#ABC"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Keyword">var</span> <span class="Identifier">num8</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"0x_4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="HexNumber">0xED'i8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"0x_4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="HexNumber">0x4E'i8</span>
- <span class="Keyword">var</span> <span class="Identifier">num8u</span><span class="Punctuation">:</span> <span class="Identifier">uint8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"0x_4E_69_ED"</span><span class="Punctuation">,</span> <span class="Identifier">num8u</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8u</span> <span class="Operator">==</span> <span class="DecNumber">237</span>
- <span class="Keyword">var</span> <span class="Identifier">num64</span><span class="Punctuation">:</span> <span class="Identifier">int64</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseHex</span><span class="Punctuation">(</span><span class="StringLit">"4E69ED4E69ED"</span><span class="Punctuation">,</span> <span class="Identifier">num64</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">12</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num64</span> <span class="Operator">==</span> <span class="DecNumber">86216859871725</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L811" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L811" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseIdent-procs-all">
- <div id="parseIdent,openArray[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseIdent%2CopenArray%5Bchar%5D"><span class="Identifier">parseIdent</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><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">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>
-
- Parses an identifier and returns it or an empty string in case of an error.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"Hello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"ello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">""</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"World"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L235" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L235" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseIdent,openArray[char],string">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseIdent%2CopenArray%5Bchar%5D%2Cstring"><span class="Identifier">parseIdent</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">ident</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="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">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>
-
- Parses an identifier and stores it in <tt class="docutils literal"><span class="pre">ident</span></tt>. Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre"><span class="Identifier">ident</span></span></tt> is not changed.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="StringLit">"Hello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="StringLit">"ello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="StringLit">"World"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L214" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L214" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseIdent,string,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseIdent%2Cstring%2Cstring%2Cint"><span class="Identifier">parseIdent</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">ident</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">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><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">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>
-
- Parses an identifier and stores it in <tt class="docutils literal"><span class="pre">ident</span></tt>. Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre"><span class="Identifier">ident</span></span></tt> is not changed.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="StringLit">"Hello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="StringLit">"ello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="StringLit">"World"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L844" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L844" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseIdent,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseIdent%2Cstring%2Cint"><span class="Identifier">parseIdent</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><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>
-
- Parses an identifier and returns it or an empty string in case of an error.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"Hello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"ello"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">""</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseIdent</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"World"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L858" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L858" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseInt-procs-all">
- <div id="parseInt,openArray[char],int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseInt%2CopenArray%5Bchar%5D%2Cint"><span class="Identifier">parseInt</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#int"><span class="Identifier">int</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">"npuParseInt"</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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an integer and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if there is no integer. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseInt</span><span class="Punctuation">(</span><span class="StringLit">"-2024_05_02"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">20240502</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L484" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L484" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseInt,string,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseInt%2Cstring%2Cint%2Cint"><span class="Identifier">parseInt</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">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an integer starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt> and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. Result is the number of processed chars or 0 if there is no integer. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseInt</span><span class="Punctuation">(</span><span class="StringLit">"-2024_05_02"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">20240502</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseInt</span><span class="Punctuation">(</span><span class="StringLit">"-2024_05_02"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">502</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1017" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1017" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseOct-procs-all">
- <div id="parseOct,openArray[char],T,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseOct%2CopenArray%5Bchar%5D%2CT%2Cint"><span class="Identifier">parseOct</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">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">maxLen</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span class="Identifier">noSideEffect</span>.}</pre></dt>
- <dd>
-
- <p>Parses an octal number and stores its value in <tt class="docutils literal"><span class="pre">number</span></tt>.</p>
- <p>Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre">number</span></tt> is not changed.</p>
- <p>If <tt class="docutils literal"><span class="pre">maxLen == 0</span></tt>, the parsing continues until the first non-oct character or to the end of the string. Otherwise, no more than <tt class="docutils literal"><span class="pre">maxLen</span></tt> characters are parsed starting from the <tt class="docutils literal"><span class="pre">start</span></tt> position.</p>
- <p>It does not check for overflow. If the value represented by the string is too big to fit into <tt class="docutils literal"><span class="pre">number</span></tt>, only the value of last fitting characters will be stored in <tt class="docutils literal"><span class="pre">number</span></tt> without producing an error.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">num</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"0o23464755"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num</span> <span class="Operator">==</span> <span class="DecNumber">5138925</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"8"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Keyword">var</span> <span class="Identifier">num8</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"0o_1464_755"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">19</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"0o_1464_755"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="DecNumber">102</span>
- <span class="Keyword">var</span> <span class="Identifier">num8u</span><span class="Punctuation">:</span> <span class="Identifier">uint8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"1464755"</span><span class="Punctuation">,</span> <span class="Identifier">num8u</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">7</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8u</span> <span class="Operator">==</span> <span class="DecNumber">237</span>
- <span class="Keyword">var</span> <span class="Identifier">num64</span><span class="Punctuation">:</span> <span class="Identifier">int64</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"2346475523464755"</span><span class="Punctuation">,</span> <span class="Identifier">num64</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">16</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num64</span> <span class="Operator">==</span> <span class="DecNumber">86216859871725</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L111" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L111" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseOct,string,T,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseOct%2Cstring%2CT%2Cint%2Cint"><span class="Identifier">parseOct</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">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">maxLen</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
- <span class="Identifier">noSideEffect</span>.}</pre></dt>
- <dd>
-
- <p>Parses an octal number and stores its value in <tt class="docutils literal"><span class="pre">number</span></tt>.</p>
- <p>Returns the number of the parsed characters or 0 in case of an error. If error, the value of <tt class="docutils literal"><span class="pre">number</span></tt> is not changed.</p>
- <p>If <tt class="docutils literal"><span class="pre">maxLen == 0</span></tt>, the parsing continues until the first non-oct character or to the end of the string. Otherwise, no more than <tt class="docutils literal"><span class="pre">maxLen</span></tt> characters are parsed starting from the <tt class="docutils literal"><span class="pre">start</span></tt> position.</p>
- <p>It does not check for overflow. If the value represented by the string is too big to fit into <tt class="docutils literal"><span class="pre">number</span></tt>, only the value of last fitting characters will be stored in <tt class="docutils literal"><span class="pre">number</span></tt> without producing an error.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">num</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"0o23464755"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num</span> <span class="Operator">==</span> <span class="DecNumber">5138925</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"8"</span><span class="Punctuation">,</span> <span class="Identifier">num</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Keyword">var</span> <span class="Identifier">num8</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"0o_1464_755"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">19</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"0o_1464_755"</span><span class="Punctuation">,</span> <span class="Identifier">num8</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8</span> <span class="Operator">==</span> <span class="DecNumber">102</span>
- <span class="Keyword">var</span> <span class="Identifier">num8u</span><span class="Punctuation">:</span> <span class="Identifier">uint8</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"1464755"</span><span class="Punctuation">,</span> <span class="Identifier">num8u</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">7</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num8u</span> <span class="Operator">==</span> <span class="DecNumber">237</span>
- <span class="Keyword">var</span> <span class="Identifier">num64</span><span class="Punctuation">:</span> <span class="Identifier">int64</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseOct</span><span class="Punctuation">(</span><span class="StringLit">"2346475523464755"</span><span class="Punctuation">,</span> <span class="Identifier">num64</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">16</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">num64</span> <span class="Operator">==</span> <span class="DecNumber">86216859871725</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L779" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L779" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseSaturatedNatural-procs-all">
- <div id="parseSaturatedNatural,openArray[char],int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseSaturatedNatural%2CopenArray%5Bchar%5D%2Cint"><span class="Identifier">parseSaturatedNatural</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">b</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#int"><span class="Identifier">int</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">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>
-
- Parses a natural number into <tt class="docutils literal"><span class="pre">b</span></tt>. This cannot raise an overflow error. <tt class="docutils literal"><span class="pre">high(int)</span></tt> is returned for an overflow. The number of processed character is returned. This is usually what you really want to use instead of <span id="parseint_1">parseInt</span>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span> <span class="Operator">=</span> <span class="DecNumber">0</span>
- <span class="Keyword">discard</span> <span class="Identifier">parseSaturatedNatural</span><span class="Punctuation">(</span><span class="StringLit">"848"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">848</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L501" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L501" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseSaturatedNatural,string,int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseSaturatedNatural%2Cstring%2Cint%2Cint"><span class="Identifier">parseSaturatedNatural</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">b</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><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">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>
-
- Parses a natural number into <tt class="docutils literal"><span class="pre">b</span></tt>. This cannot raise an overflow error. <tt class="docutils literal"><span class="pre">high(int)</span></tt> is returned for an overflow. The number of processed character is returned. This is usually what you really want to use instead of <span id="parseint_2">parseInt</span>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span> <span class="Operator">=</span> <span class="DecNumber">0</span>
- <span class="Keyword">discard</span> <span class="Identifier">parseSaturatedNatural</span><span class="Punctuation">(</span><span class="StringLit">"848"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">848</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1030" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1030" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseSize-procs-all">
- <div id="parseSize,openArray[char],int64">
- <dt><pre><span class="Keyword">func</span> <a href="#parseSize%2CopenArray%5Bchar%5D%2Cint64"><span class="Identifier">parseSize</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#int64"><span class="Identifier">int64</span></a><span class="Other">;</span> <span class="Identifier">alwaysBin</span> <span class="Other">=</span> <span class="Identifier">false</span><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">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>Parse a size qualified by binary or metric units into <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt>. This format is often called "human readable". Result is the number of processed chars or 0 on parse errors and size is rounded to the nearest integer. Trailing garbage like "/s" in "1k/s" is allowed and detected by <tt class="docutils literal"><span class="pre"><span class="Identifier">result</span> <span class="Operator"><</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">len</span></span></tt>.</p>
- <p>To simplify use, following non-rare wild conventions, and since fractional data like milli-bytes is so rare, unit matching is case-insensitive but for the 'i' distinguishing binary-metric from metric (which cannot be 'I').</p>
- <p>An optional trailing 'B|b' is ignored but processed. I.e., you must still know if units are bytes | bits or infer this fact via the case of s<sup><strong><a class="reference internal" href="#footnote-1">[1]</a></strong></sup> (if users can even be relied upon to use 'B' for byte and 'b' for bit or have that be s<sup><strong><a class="reference internal" href="#footnote-1">[1]</a></strong></sup>).</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">alwaysBin</span><span class="Operator">==</span><span class="Identifier">true</span></span></tt> then scales are always binary-metric, but e.g. "KiB" is still accepted for clarity. If the value would exceed the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">int64</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> saturates to <tt class="docutils literal"><span class="pre"><span class="Identifier">int64</span><span class="Operator">.</span><span class="Identifier">high</span></span></tt>. Supported metric prefix chars include k, m, g, t, p, e, z, y (but z & y saturate unless the number is a small fraction).</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="https://en.wikipedia.org/wiki/Binary_prefix">https://en.wikipedia.org/wiki/Binary_prefix</a></li>
- <li><a class="reference external" href="strutils.html">formatSize module</a> for formatting</li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">int64</span> <span class="Comment"># caller must still know if 'b' refers to bytes|bits</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseSize</span><span class="Punctuation">(</span><span class="StringLit">"10.5 MB"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">7</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">10_500_000</span> <span class="Comment"># decimal metric Mega prefix</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseSize</span><span class="Punctuation">(</span><span class="StringLit">"64 mib"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">67108864</span> <span class="Comment"># 64 shl 20</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseSize</span><span class="Punctuation">(</span><span class="StringLit">"1G/h"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="Identifier">true</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span> <span class="Comment"># '/' stops parse</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">1073741824</span> <span class="Comment"># 1 shl 30, forced binary metric</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L613" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L613" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseUInt-procs-all">
- <div id="parseUInt,openArray[char],uint">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUInt%2CopenArray%5Bchar%5D%2Cuint"><span class="Identifier">parseUInt</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#uint"><span class="Identifier">uint</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">"npuParseUInt"</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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an unsigned integer and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">uint</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUInt</span><span class="Punctuation">(</span><span class="StringLit">"3450"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">3450</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUInt</span><span class="Punctuation">(</span><span class="StringLit">"3450"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">50</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L567" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L567" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseUInt,string,uint,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUInt%2Cstring%2Cuint%2Cint"><span class="Identifier">parseUInt</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">number</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#uint"><span class="Identifier">uint</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<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><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><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>
-
- Parses an unsigned integer starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt> and stores the value into <tt class="docutils literal"><span class="pre"><span class="Identifier">number</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is raised if the parsed integer is out of the valid range.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span><span class="Punctuation">:</span> <span class="Identifier">uint</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUInt</span><span class="Punctuation">(</span><span class="StringLit">"3450"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">3450</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUInt</span><span class="Punctuation">(</span><span class="StringLit">"3450"</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">res</span> <span class="Operator">==</span> <span class="DecNumber">50</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1055" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1055" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseUntil-procs-all">
- <div id="parseUntil,openArray[char],string,char">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUntil%2CopenArray%5Bchar%5D%2Cstring%2Cchar"><span class="Identifier">parseUntil</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">token</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">until</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of any character that is not the <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> character.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="CharLit">'W'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hello "</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hell"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"ll"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L358" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L358" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseUntil,openArray[char],string,set[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUntil%2CopenArray%5Bchar%5D%2Cstring%2Cset%5Bchar%5D"><span class="Identifier">parseUntil</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">token</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">until</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of the characters notin <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}) == 4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hell"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}) == 6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hello "</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 3) == 3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"lo "</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L340" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L340" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseUntil,openArray[char],string,string">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUntil%2CopenArray%5Bchar%5D%2Cstring%2Cstring"><span class="Identifier">parseUntil</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">token</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">until</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#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of any character that comes before the <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> token.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="StringLit">"Wor"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hello "</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="StringLit">"Wor"</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"llo "</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L376" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L376" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseUntil,string,string,char,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUntil%2Cstring%2Cstring%2Cchar%2Cint"><span class="Identifier">parseUntil</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">token</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">until</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of any character that is not the <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> character.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="CharLit">'W'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hello "</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hell"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"ll"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L953" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L953" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseUntil,string,string,set[char],int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUntil%2Cstring%2Cstring%2Cset%5Bchar%5D%2Cint"><span class="Identifier">parseUntil</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">token</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">until</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of the characters notin <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}) == 4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hell"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}) == 6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hello "</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 3) == 3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"lo "</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L938" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L938" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseUntil,string,string,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseUntil%2Cstring%2Cstring%2Cstring%2Cint"><span class="Identifier">parseUntil</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">token</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">until</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><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of any character that comes before the <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> token.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="StringLit">"Wor"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Hello "</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="StringLit">"Wor"</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"llo "</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L968" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L968" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parseWhile-procs-all">
- <div id="parseWhile,openArray[char],string,set[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseWhile%2CopenArray%5Bchar%5D%2Cstring%2Cset%5Bchar%5D"><span class="Identifier">parseWhile</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">token</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">validChars</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of the characters in <tt class="docutils literal"><span class="pre"><span class="Identifier">validChars</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 0) == 0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span><span class="Operator">.</span><span class="Identifier">len</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 6) == 3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Wor"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L402" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L402" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="parseWhile,string,string,set[char],int">
- <dt><pre><span class="Keyword">proc</span> <a href="#parseWhile%2Cstring%2Cstring%2Cset%5Bchar%5D%2Cint"><span class="Identifier">parseWhile</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">token</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">validChars</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Parses a token and stores it in <tt class="docutils literal"><span class="pre">token</span></tt>. Returns the number of the parsed characters or 0 in case of an error. A token consists of the characters in <tt class="docutils literal"><span class="pre"><span class="Identifier">validChars</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">myToken</span><span class="Punctuation">:</span> <span class="Identifier">string</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 0) == 0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span><span class="Operator">.</span><span class="Identifier">len</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">parseWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Identifier">myToken</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 6) == 3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">myToken</span> <span class="Operator">==</span> <span class="StringLit">"Wor"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L981" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L981" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="skip-procs-all">
- <div id="skip,openArray[char],openArray[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#skip%2CopenArray%5Bchar%5D%2CopenArray%5Bchar%5D"><span class="Identifier">skip</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">token</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips the <tt class="docutils literal"><span class="pre"><span class="Identifier">token</span></span></tt> starting at <tt class="docutils literal"><span class="pre">s[start]</span></tt>. Returns the length of <tt class="docutils literal"><span class="pre"><span class="Identifier">token</span></span></tt> or 0 if there was no <tt class="docutils literal"><span class="pre"><span class="Identifier">token</span></span></tt> at <tt class="docutils literal"><span class="pre">s[start]</span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"2019-01-22"</span><span class="Punctuation">,</span> <span class="StringLit">"2019"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"2019-01-22"</span><span class="Punctuation">,</span> <span class="StringLit">"19"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"2019-01-22"</span><span class="Punctuation">,</span> <span class="StringLit">"19"</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"CAP"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"cap"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L278" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L278" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="skip,string,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#skip%2Cstring%2Cstring%2Cint"><span class="Identifier">skip</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">token</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><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips the <tt class="docutils literal"><span class="pre"><span class="Identifier">token</span></span></tt> starting at <tt class="docutils literal"><span class="pre">s[start]</span></tt>. Returns the length of <tt class="docutils literal"><span class="pre"><span class="Identifier">token</span></span></tt> or 0 if there was no <tt class="docutils literal"><span class="pre"><span class="Identifier">token</span></span></tt> at <tt class="docutils literal"><span class="pre">s[start]</span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"2019-01-22"</span><span class="Punctuation">,</span> <span class="StringLit">"2019"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"2019-01-22"</span><span class="Punctuation">,</span> <span class="StringLit">"19"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"2019-01-22"</span><span class="Punctuation">,</span> <span class="StringLit">"19"</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"CAP"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skip</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"cap"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L890" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L890" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="skipIgnoreCase-procs-all">
- <div id="skipIgnoreCase,openArray[char],openArray[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipIgnoreCase%2CopenArray%5Bchar%5D%2CopenArray%5Bchar%5D"><span class="Identifier">skipIgnoreCase</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">token</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><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">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>
-
- Same as <tt class="docutils literal"><span class="pre"><span class="Identifier">skip</span></span></tt> but case is ignored for token matching.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipIgnoreCase</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"CAP"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipIgnoreCase</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"cap"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L293" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L293" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="skipIgnoreCase,string,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipIgnoreCase%2Cstring%2Cstring%2Cint"><span class="Identifier">skipIgnoreCase</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">token</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><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">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>
-
- Same as <tt class="docutils literal"><span class="pre"><span class="Identifier">skip</span></span></tt> but case is ignored for token matching.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipIgnoreCase</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"CAP"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipIgnoreCase</span><span class="Punctuation">(</span><span class="StringLit">"CAPlow"</span><span class="Punctuation">,</span> <span class="StringLit">"cap"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L901" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L901" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="skipUntil-procs-all">
- <div id="skipUntil,openArray[char],char">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipUntil%2CopenArray%5Bchar%5D%2Cchar"><span class="Identifier">skipUntil</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">until</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips all characters until the char <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> is found or the end is reached. Returns number of characters skipped.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'W'</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'w'</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L314" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L314" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="skipUntil,openArray[char],set[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipUntil%2CopenArray%5Bchar%5D%2Cset%5Bchar%5D"><span class="Identifier">skipUntil</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">until</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips all characters until one char from the set <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> is found or the end is reached. Returns number of characters skipped.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">'}, 0) == 1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">'}, 0) == 6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">d</span><span class="CharLit">'}, 0) == 6</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L303" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L303" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="skipUntil,string,char,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipUntil%2Cstring%2Cchar%2Cint"><span class="Identifier">skipUntil</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">until</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips all characters until the char <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> is found or the end is reached. Returns number of characters skipped.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'o'</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'W'</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="CharLit">'w'</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">11</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L918" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L918" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="skipUntil,string,set[char],int">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipUntil%2Cstring%2Cset%5Bchar%5D%2Cint"><span class="Identifier">skipUntil</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">until</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips all characters until one char from the set <tt class="docutils literal"><span class="pre"><span class="Identifier">until</span></span></tt> is found or the end is reached. Returns number of characters skipped.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">'}, 0) == 1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">'}, 0) == 6</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipUntil</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">d</span><span class="CharLit">'}, 0) == 6</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L908" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L908" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="skipWhile-procs-all">
- <div id="skipWhile,openArray[char],set[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipWhile%2CopenArray%5Bchar%5D%2Cset%5Bchar%5D"><span class="Identifier">skipWhile</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">toSkip</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips all characters while one char from the set <tt class="docutils literal"><span class="pre"><span class="Identifier">toSkip</span></span></tt> is found. Returns number of characters skipped.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">H</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">'}) == 2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">e</span><span class="CharLit">'}) == 0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 6) == 3</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L326" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L326" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="skipWhile,string,set[char],int">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipWhile%2Cstring%2Cset%5Bchar%5D%2Cint"><span class="Identifier">skipWhile</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">toSkip</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips all characters while one char from the set <tt class="docutils literal"><span class="pre"><span class="Identifier">toSkip</span></span></tt> is found. Returns number of characters skipped.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">H</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">'}) == 2</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">e</span><span class="CharLit">'}) == 0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhile</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">W</span><span class="CharLit">', '</span><span class="Identifier">o</span><span class="CharLit">', '</span><span class="Identifier">r</span><span class="CharLit">'}, 6) == 3</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L929" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L929" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="skipWhitespace-procs-all">
- <div id="skipWhitespace,openArray[char]">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipWhitespace%2CopenArray%5Bchar%5D"><span class="Identifier">skipWhitespace</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips the whitespace starting at <tt class="docutils literal"><span class="pre">s[start]</span></tt>. Returns the number of skipped characters.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">" Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L267" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L267" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="skipWhitespace,string,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#skipWhitespace%2Cstring%2Cint"><span class="Identifier">skipWhitespace</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><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
-
- Skips the whitespace starting at <tt class="docutils literal"><span class="pre">s[start]</span></tt>. Returns the number of skipped characters.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">" Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">skipWhitespace</span><span class="Punctuation">(</span><span class="StringLit">"Hello World"</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L880" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L880" 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="interpolatedFragments-iterators-all">
- <div id="interpolatedFragments.i,openArray[char]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#interpolatedFragments.i%2CopenArray%5Bchar%5D"><span class="Identifier">interpolatedFragments</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span>
- <span class="Identifier">kind</span><span class="Other">:</span> <a href="parseutils.html#InterpolatedKind"><span class="Identifier">InterpolatedKind</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><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>
- <dd>
-
- Tokenizes the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into substrings for interpolation purposes.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">outp</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Keyword">tuple</span><span class="Punctuation">[</span><span class="Identifier">kind</span><span class="Punctuation">:</span> <span class="Identifier">InterpolatedKind</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">]</span>
- <span class="Keyword">for</span> <span class="Identifier">k</span><span class="Punctuation">,</span> <span class="Identifier">v</span> <span class="Keyword">in</span> <span class="Identifier">interpolatedFragments</span><span class="Punctuation">(</span><span class="StringLit">" $this is ${an example} $$"</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
- <span class="Identifier">outp</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Punctuation">(</span><span class="Identifier">k</span><span class="Punctuation">,</span> <span class="Identifier">v</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">outp</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="Identifier">ikStr</span><span class="Punctuation">,</span> <span class="StringLit">" "</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikVar</span><span class="Punctuation">,</span> <span class="StringLit">"this"</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikStr</span><span class="Punctuation">,</span> <span class="StringLit">" is "</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikExpr</span><span class="Punctuation">,</span> <span class="StringLit">"an example"</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikStr</span><span class="Punctuation">,</span> <span class="StringLit">" "</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikDollar</span><span class="Punctuation">,</span> <span class="StringLit">"$"</span><span class="Punctuation">)</span><span class="Punctuation">]</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L684" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L684" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="interpolatedFragments.i,string">
- <dt><pre><span class="Keyword">iterator</span> <a href="#interpolatedFragments.i%2Cstring"><span class="Identifier">interpolatedFragments</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="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">kind</span><span class="Other">:</span> <a href="parseutils.html#InterpolatedKind"><span class="Identifier">InterpolatedKind</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><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>
- <dd>
-
- Tokenizes the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into substrings for interpolation purposes.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">outp</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Keyword">tuple</span><span class="Punctuation">[</span><span class="Identifier">kind</span><span class="Punctuation">:</span> <span class="Identifier">InterpolatedKind</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">]</span>
- <span class="Keyword">for</span> <span class="Identifier">k</span><span class="Punctuation">,</span> <span class="Identifier">v</span> <span class="Keyword">in</span> <span class="Identifier">interpolatedFragments</span><span class="Punctuation">(</span><span class="StringLit">" $this is ${an example} $$"</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
- <span class="Identifier">outp</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Punctuation">(</span><span class="Identifier">k</span><span class="Punctuation">,</span> <span class="Identifier">v</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">outp</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="Identifier">ikStr</span><span class="Punctuation">,</span> <span class="StringLit">" "</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikVar</span><span class="Punctuation">,</span> <span class="StringLit">"this"</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikStr</span><span class="Punctuation">,</span> <span class="StringLit">" is "</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikExpr</span><span class="Punctuation">,</span> <span class="StringLit">"an example"</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikStr</span><span class="Punctuation">,</span> <span class="StringLit">" "</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
- <span class="Punctuation">(</span><span class="Identifier">ikDollar</span><span class="Punctuation">,</span> <span class="StringLit">"$"</span><span class="Punctuation">)</span><span class="Punctuation">]</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parseutils.nim#L1087" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parseutils.nim#L1087" 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: 2024-12-25 13:27:44 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|