CSV/docs/Structs/Parser.html

487 lines
24 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Parser Structure Reference</title>
<link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="../css/highlight.css" />
<meta charset='utf-8'>
<script src="../js/jquery.min.js" defer></script>
<script src="../js/jazzy.js" defer></script>
<script src="../js/lunr.min.js" defer></script>
<script src="../js/typeahead.jquery.js" defer></script>
<script src="../js/jazzy.search.js" defer></script>
</head>
<body>
<a name="//apple_ref/swift/Struct/Parser" class="dashAnchor"></a>
<a title="Parser Structure Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html"> Docs</a> (100% documented)</p>
<div class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</div>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="../index.html"> Reference</a>
<img id="carat" src="../img/carat.png" alt=""/>
Parser Structure Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Classes/CSVAsyncDecoder.html">CSVAsyncDecoder</a>
</li>
<li class="nav-group-task">
<a href="../Classes/CSVAsyncEncoder.html">CSVAsyncEncoder</a>
</li>
<li class="nav-group-task">
<a href="../Classes/CSVCodingOptions.html">CSVCodingOptions</a>
</li>
<li class="nav-group-task">
<a href="../Classes/CSVDecoder.html">CSVDecoder</a>
</li>
<li class="nav-group-task">
<a href="../Classes/CSVEncoder.html">CSVEncoder</a>
</li>
<li class="nav-group-task">
<a href="../Classes/CSVSyncDecoder.html">CSVSyncDecoder</a>
</li>
<li class="nav-group-task">
<a href="../Classes/CSVSyncEncoder.html">CSVSyncEncoder</a>
</li>
<li class="nav-group-task">
<a href="../Classes/SyncParser.html">SyncParser</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Enums.html">Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Enums/BoolCodingStrategy.html">BoolCodingStrategy</a>
</li>
<li class="nav-group-task">
<a href="../Enums/NilCodingStrategy.html">NilCodingStrategy</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Extensions.html">Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Extensions/Array.html">Array</a>
</li>
<li class="nav-group-task">
<a href="../Extensions.html#/s:SD">Dictionary</a>
</li>
<li class="nav-group-task">
<a href="../Extensions/Optional.html">Optional</a>
</li>
<li class="nav-group-task">
<a href="../Extensions/String.html">String</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Protocols/BytesRepresentable.html">BytesRepresentable</a>
</li>
<li class="nav-group-task">
<a href="../Protocols/KeyedCollection.html">KeyedCollection</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Structs/Config.html">Config</a>
</li>
<li class="nav-group-task">
<a href="../Structs/ErrorList.html">ErrorList</a>
</li>
<li class="nav-group-task">
<a href="../Structs/Parser.html">Parser</a>
</li>
<li class="nav-group-task">
<a href="../Structs/Serializer.html">Serializer</a>
</li>
<li class="nav-group-task">
<a href="../Structs/SyncSerializer.html">SyncSerializer</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1>Parser</h1>
<div class="declaration">
<div class="language">
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">Parser</span></code></pre>
</div>
</div>
<p>A parser for streaming <code>CSV</code> data.</p>
<div class="aside aside-note">
<p class="aside-title">Note</p>
You should create a new <code>Parser</code> instance for each CSV document you parse.
</div>
</section>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:3CSV6ParserV13HeaderHandlera"></a>
<a name="//apple_ref/swift/Alias/HeaderHandler" class="dashAnchor"></a>
<a class="token" href="#/s:3CSV6ParserV13HeaderHandlera">HeaderHandler</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The type of handler that gets called when a header is parsed.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">HeaderHandler</span> <span class="o">=</span> <span class="p">(</span><span class="n">_</span> <span class="nv">title</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">])</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="p">()</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>title</em>
</code>
</td>
<td>
<div>
<p>The data for the header that is parsed.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:3CSV6ParserV11CellHandlera"></a>
<a name="//apple_ref/swift/Alias/CellHandler" class="dashAnchor"></a>
<a class="token" href="#/s:3CSV6ParserV11CellHandlera">CellHandler</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The type of handler that gets called when a cell is parsed.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">CellHandler</span> <span class="o">=</span> <span class="p">(</span><span class="n">_</span> <span class="nv">title</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">],</span> <span class="n">_</span> <span class="nv">contents</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">])</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="p">()</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>title</em>
</code>
</td>
<td>
<div>
<p>The header for the cell that is parsed.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>contents</em>
</code>
</td>
<td>
<div>
<p>The data for the cell that is parsed.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:3CSV6ParserV8onHeaderySays5UInt8VGKcSgvp"></a>
<a name="//apple_ref/swift/Property/onHeader" class="dashAnchor"></a>
<a class="token" href="#/s:3CSV6ParserV8onHeaderySays5UInt8VGKcSgvp">onHeader</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The callback that is called when a header is parsed.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">onHeader</span><span class="p">:</span> <span class="kt"><a href="../Structs/Parser.html#/s:3CSV6ParserV13HeaderHandlera">HeaderHandler</a></span><span class="p">?</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:3CSV6ParserV6onCellySays5UInt8VG_AGtKcSgvp"></a>
<a name="//apple_ref/swift/Property/onCell" class="dashAnchor"></a>
<a class="token" href="#/s:3CSV6ParserV6onCellySays5UInt8VG_AGtKcSgvp">onCell</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The callback that is called when a cell is parsed.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">onCell</span><span class="p">:</span> <span class="kt"><a href="../Structs/Parser.html#/s:3CSV6ParserV11CellHandlera">CellHandler</a></span><span class="p">?</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:3CSV6ParserV13configurationAA6ConfigVvp"></a>
<a name="//apple_ref/swift/Property/configuration" class="dashAnchor"></a>
<a class="token" href="#/s:3CSV6ParserV13configurationAA6ConfigVvp">configuration</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The struct that configures parsing options</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">configuration</span><span class="p">:</span> <span class="kt"><a href="../Structs/Config.html">Config</a></span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:3CSV6ParserV8onHeader0C4Cell13configurationACySays5UInt8VGKcSg_yAI_AItKcSgAA6ConfigVtcfc"></a>
<a name="//apple_ref/swift/Method/init(onHeader:onCell:configuration:)" class="dashAnchor"></a>
<a class="token" href="#/s:3CSV6ParserV8onHeader0C4Cell13configurationACySays5UInt8VGKcSg_yAI_AItKcSgAA6ConfigVtcfc">init(onHeader:<wbr>onCell:<wbr>configuration:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Creates a new <code>Parser</code> instance.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span><span class="nv">onHeader</span><span class="p">:</span> <span class="kt"><a href="../Structs/Parser.html#/s:3CSV6ParserV13HeaderHandlera">HeaderHandler</a></span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span> <span class="nv">onCell</span><span class="p">:</span> <span class="kt"><a href="../Structs/Parser.html#/s:3CSV6ParserV11CellHandlera">CellHandler</a></span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span> <span class="nv">configuration</span><span class="p">:</span> <span class="kt"><a href="../Structs/Config.html">Config</a></span> <span class="o">=</span> <span class="kt"><a href="../Structs/Config.html">Config</a></span><span class="o">.</span><span class="k">default</span><span class="p">)</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>onHeader</em>
</code>
</td>
<td>
<div>
<p>The callback that will be called when a header is parsed.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>onCell</em>
</code>
</td>
<td>
<div>
<p>The callback that will be called when a cell is parsed.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>configuration</em>
</code>
</td>
<td>
<div>
<p>The struct that configures parsing options</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:3CSV6ParserV5parse_6lengths6ResultOyytAA9ErrorListVGSays5UInt8VG_SiSgtF"></a>
<a name="//apple_ref/swift/Method/parse(_:length:)" class="dashAnchor"></a>
<a class="token" href="#/s:3CSV6ParserV5parse_6lengths6ResultOyytAA9ErrorListVGSays5UInt8VG_SiSgtF">parse(_:<wbr>length:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Parses an arbitrary portion of a CSV document.</p>
<p>The data passed in should be the next slice of the document directly after the previous one.</p>
<p>When a header is parsed from the data, the data will be passed into the registered <code><a href="../Structs/Parser.html#/s:3CSV6ParserV8onHeaderySays5UInt8VGKcSgvp">.onHeader</a></code> callback.
When a cell is parsed from the data, the header for that given cell and the cell&rsquo;s data will be passed into
the <code><a href="../Structs/Parser.html#/s:3CSV6ParserV6onCellySays5UInt8VG_AGtKcSgvp">.onCell</a></code> callback.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="kd">public</span> <span class="k">mutating</span> <span class="kd">func</span> <span class="nf">parse</span><span class="p">(</span><span class="n">_</span> <span class="nv">data</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">],</span> <span class="nv">length</span><span class="p">:</span> <span class="kt">Int</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Void</span><span class="p">,</span> <span class="kt"><a href="../Structs/ErrorList.html">ErrorList</a></span><span class="o">&gt;</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>data</em>
</code>
</td>
<td>
<div>
<p>The portion of the CSV document to parse.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>length</em>
</code>
</td>
<td>
<div>
<p>The full content length of the document that is being parsed.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<h4>Return Value</h4>
<p>A <code>Result</code> instance that will have a <code>.failure</code> case with all the errors thrown from
the registered callbacks. If there are no errors, then the result will be a <code>.success</code> case.</p>
</div>
</section>
</div>
</li>
</ul>
</div>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external noopener"></a>. All rights reserved. (Last updated: 2021-10-20)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</html>