mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
252 lines
26 KiB
HTML
252 lines
26 KiB
HTML
<?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/encodings</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/encodings</h1>
|
|
<div class="row">
|
|
<div class="three columns">
|
|
<div class="theme-select-wrapper">
|
|
<label for="theme-select">Theme: </label>
|
|
<select id="theme-select" onchange="setTheme(this.value)">
|
|
<option value="auto">🌗 Match OS</option>
|
|
<option value="dark">🌑 Dark</option>
|
|
<option value="light">🌕 Light</option>
|
|
</select>
|
|
</div>
|
|
<div id="global-links">
|
|
<ul class="simple-boot">
|
|
<li><a href="manual.html">Manual</a></li>
|
|
<li><a href="lib.html">Standard library</a></li>
|
|
<li> <a id="indexLink" href="theindex.html">Index</a></li>
|
|
<li><a href="compiler/theindex.html">Compiler docs</a></li>
|
|
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
|
|
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="searchInputDiv">
|
|
Search: <input type="search" id="searchInput"
|
|
oninput="search()" />
|
|
</div>
|
|
|
|
<ul class="simple simple-toc" id="toc-list">
|
|
<li>
|
|
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<li><a class="reference" href="#EncodingConverter" title="EncodingConverter = ptr ConverterObj">EncodingConverter</a></li>
|
|
<li><a class="reference" href="#EncodingError" title="EncodingError = object of ValueError">EncodingError</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">close
|
|
<li><a class="reference" href="#close%2CEncodingConverter" title="close(c: EncodingConverter)">close(c: EncodingConverter)</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">convert
|
|
<li><a class="reference" href="#convert%2CEncodingConverter%2Cstring" title="convert(c: EncodingConverter; s: string): string">convert(c: EncodingConverter; s: string): string</a></li>
|
|
<li><a class="reference" href="#convert%2Cstring%2Cstring%2Cstring" title="convert(s: string; destEncoding = "UTF-8"; srcEncoding = "CP1252"): string">convert(s: string; destEncoding = "UTF-8"; srcEncoding = "CP1252"): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">getCurrentEncoding
|
|
<li><a class="reference" href="#getCurrentEncoding" title="getCurrentEncoding(uiApp = false): string">getCurrentEncoding(uiApp = false): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">open
|
|
<li><a class="reference" href="#open%2Cstring%2Cstring" title="open(destEncoding = "UTF-8"; srcEncoding = "CP1252"): EncodingConverter">open(destEncoding = "UTF-8"; srcEncoding = "CP1252"): EncodingConverter</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/encodings.nim#L1" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
<div id="tocRoot"></div>
|
|
|
|
<p class="module-desc"><p>Routines for converting between different character encodings. On UNIX, this uses the <span id="iconv_1">iconv</span> library, on Windows the Windows API.</p>
|
|
<p>The following example shows how to change character encodings.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">encodings</span>
|
|
<span class="Keyword">when</span> <span class="Identifier">defined</span><span class="Punctuation">(</span><span class="Identifier">windows</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
|
|
<span class="Keyword">let</span>
|
|
<span class="Identifier">orig</span> <span class="Operator">=</span> <span class="StringLit">"öäüß"</span>
|
|
<span class="Comment"># convert `orig` from "UTF-8" to "CP1252"</span>
|
|
<span class="Identifier">cp1252</span> <span class="Operator">=</span> <span class="Identifier">convert</span><span class="Punctuation">(</span><span class="Identifier">orig</span><span class="Punctuation">,</span> <span class="StringLit">"CP1252"</span><span class="Punctuation">,</span> <span class="StringLit">"UTF-8"</span><span class="Punctuation">)</span>
|
|
<span class="Comment"># convert `cp1252` from "CP1252" to "ibm850"</span>
|
|
<span class="Identifier">ibm850</span> <span class="Operator">=</span> <span class="Identifier">convert</span><span class="Punctuation">(</span><span class="Identifier">cp1252</span><span class="Punctuation">,</span> <span class="StringLit">"ibm850"</span><span class="Punctuation">,</span> <span class="StringLit">"CP1252"</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">current</span> <span class="Operator">=</span> <span class="Identifier">getCurrentEncoding</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">orig</span> <span class="Operator">==</span> <span class="StringLit">"</span><span class="EscapeSequence">\195</span><span class="EscapeSequence">\182</span><span class="EscapeSequence">\195</span><span class="EscapeSequence">\164</span><span class="EscapeSequence">\195</span><span class="EscapeSequence">\188</span><span class="EscapeSequence">\195</span><span class="EscapeSequence">\159</span><span class="StringLit">"</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">ibm850</span> <span class="Operator">==</span> <span class="StringLit">"</span><span class="EscapeSequence">\148</span><span class="EscapeSequence">\132</span><span class="EscapeSequence">\129</span><span class="EscapeSequence">\225</span><span class="StringLit">"</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">convert</span><span class="Punctuation">(</span><span class="Identifier">ibm850</span><span class="Punctuation">,</span> <span class="Identifier">current</span><span class="Punctuation">,</span> <span class="StringLit">"ibm850"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">orig</span></pre>The example below uses a reuseable <tt class="docutils literal"><span class="pre"><span class="Identifier">EncodingConverter</span></span></tt> object which is created by <tt class="docutils literal"><span class="pre"><span class="Identifier">open</span></span></tt> with <tt class="docutils literal"><span class="pre"><span class="Identifier">destEncoding</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">srcEncoding</span></span></tt> specified. You can use <tt class="docutils literal"><span class="pre"><span class="Identifier">convert</span></span></tt> on this object multiple times.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">encodings</span>
|
|
<span class="Keyword">when</span> <span class="Identifier">defined</span><span class="Punctuation">(</span><span class="Identifier">windows</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
|
|
<span class="Keyword">var</span> <span class="Identifier">fromGB2312</span> <span class="Operator">=</span> <span class="Identifier">open</span><span class="Punctuation">(</span><span class="StringLit">"utf-8"</span><span class="Punctuation">,</span> <span class="StringLit">"gb2312"</span><span class="Punctuation">)</span>
|
|
<span class="Keyword">let</span> <span class="Identifier">first</span> <span class="Operator">=</span> <span class="StringLit">"</span><span class="EscapeSequence">\203</span><span class="EscapeSequence">\173</span><span class="EscapeSequence">\197</span><span class="EscapeSequence">\194</span><span class="EscapeSequence">\163</span><span class="EscapeSequence">\191</span><span class="EscapeSequence">\210</span><span class="EscapeSequence">\187</span><span class="StringLit">"</span> <span class="Operator">&</span>
|
|
<span class="StringLit">"</span><span class="EscapeSequence">\203</span><span class="EscapeSequence">\242</span><span class="EscapeSequence">\209</span><span class="EscapeSequence">\204</span><span class="EscapeSequence">\211</span><span class="EscapeSequence">\234</span><span class="EscapeSequence">\200</span><span class="EscapeSequence">\206</span><span class="EscapeSequence">\198</span><span class="EscapeSequence">\189</span><span class="EscapeSequence">\201</span><span class="EscapeSequence">\250</span><span class="StringLit">"</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">fromGB2312</span><span class="Operator">.</span><span class="Identifier">convert</span><span class="Punctuation">(</span><span class="Identifier">first</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"谁怕?一蓑烟雨任平生"</span>
|
|
|
|
<span class="Keyword">let</span> <span class="Identifier">second</span> <span class="Operator">=</span> <span class="StringLit">"</span><span class="EscapeSequence">\211</span><span class="EscapeSequence">\208</span><span class="EscapeSequence">\176</span><span class="EscapeSequence">\215</span><span class="EscapeSequence">\205</span><span class="EscapeSequence">\183</span><span class="EscapeSequence">\200</span><span class="EscapeSequence">\231</span><span class="StringLit">"</span> <span class="Operator">&</span>
|
|
<span class="StringLit">"</span><span class="EscapeSequence">\208</span><span class="EscapeSequence">\194</span><span class="EscapeSequence">\163</span><span class="EscapeSequence">\172</span><span class="EscapeSequence">\199</span><span class="EscapeSequence">\227</span><span class="EscapeSequence">\184</span><span class="EscapeSequence">\199</span><span class="EscapeSequence">\200</span><span class="EscapeSequence">\231</span><span class="EscapeSequence">\185</span><span class="EscapeSequence">\202</span><span class="StringLit">"</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">fromGB2312</span><span class="Operator">.</span><span class="Identifier">convert</span><span class="Punctuation">(</span><span class="Identifier">second</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"有白头如新,倾盖如故"</span></pre></p>
|
|
<div class="section" id="6">
|
|
<h1><a class="toc-backref" href="#6">Imports</a></h1>
|
|
<dl class="item">
|
|
<a class="reference external" href="os.html">os</a>, <a class="reference external" href="assertions.html">assertions</a>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="7">
|
|
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
|
<dl class="item">
|
|
<div id="EncodingConverter">
|
|
<dt><pre><a href="encodings.html#EncodingConverter"><span class="Identifier">EncodingConverter</span></a> <span class="Other">=</span> <span class="Keyword">ptr</span> <span class="Identifier">ConverterObj</span></pre></dt>
|
|
<dd>
|
|
|
|
Can convert between two character sets.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/encodings.nim#L49" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L49" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="EncodingError">
|
|
<dt><pre><a href="encodings.html#EncodingError"><span class="Identifier">EncodingError</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a></pre></dt>
|
|
<dd>
|
|
|
|
Exception that is raised for encoding errors.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/encodings.nim#L58" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L58" 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="close-procs-all">
|
|
<div id="close,EncodingConverter">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#close%2CEncodingConverter"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="encodings.html#EncodingConverter"><span class="Identifier">EncodingConverter</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Frees the resources the converter <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt> holds.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/encodings.nim#L359" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L359" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="convert-procs-all">
|
|
<div id="convert,EncodingConverter,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#convert%2CEncodingConverter%2Cstring"><span class="Identifier">convert</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="encodings.html#EncodingConverter"><span class="Identifier">EncodingConverter</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> <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="Identifier">OSError</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>
|
|
|
|
Converts <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">destEncoding</span></span></tt> that was given to the converter <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt>. It assumes that <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> is in <tt class="docutils literal"><span class="pre"><span class="Identifier">srcEncoding</span></span></tt>.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
|
|
UTF-16BE and UTF-32 conversions are not supported on Windows.</div>
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/encodings.nim#L457" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L457" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="convert,string,string,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#convert%2Cstring%2Cstring%2Cstring"><span class="Identifier">convert</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">destEncoding</span> <span class="Other">=</span> <span class="StringLit">"UTF-8"</span><span class="Other">;</span> <span class="Identifier">srcEncoding</span> <span class="Other">=</span> <span class="StringLit">"CP1252"</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="Identifier">EncodingError</span><span class="Other">,</span> <span class="Identifier">OSError</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>
|
|
|
|
Converts <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">destEncoding</span></span></tt>. It assumed that <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> is in <tt class="docutils literal"><span class="pre"><span class="Identifier">srcEncoding</span></span></tt>. This opens a converter, uses it and closes it again and is thus more convenient but also likely less efficient than re-using a converter.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
|
|
UTF-16BE and UTF-32 conversions are not supported on Windows.</div>
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/encodings.nim#L500" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L500" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="getCurrentEncoding-procs-all">
|
|
<div id="getCurrentEncoding">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#getCurrentEncoding"><span class="Identifier">getCurrentEncoding</span></a><span class="Other">(</span><span class="Identifier">uiApp</span> <span class="Other">=</span> <span class="Identifier">false</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>
|
|
|
|
Retrieves the current encoding. On Unix, "UTF-8" is always returned. The <tt class="docutils literal"><span class="pre"><span class="Identifier">uiApp</span></span></tt> parameter is Windows specific. If true, the UI's code-page is returned, if false, the Console's code-page is returned.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/encodings.nim#L331" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L331" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="open-procs-all">
|
|
<div id="open,string,string">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#open%2Cstring%2Cstring"><span class="Identifier">open</span></a><span class="Other">(</span><span class="Identifier">destEncoding</span> <span class="Other">=</span> <span class="StringLit">"UTF-8"</span><span class="Other">;</span> <span class="Identifier">srcEncoding</span> <span class="Other">=</span> <span class="StringLit">"CP1252"</span><span class="Other">)</span><span class="Other">:</span> <a href="encodings.html#EncodingConverter"><span class="Identifier">EncodingConverter</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="Identifier">EncodingError</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>
|
|
|
|
Opens a converter that can convert from <tt class="docutils literal"><span class="pre"><span class="Identifier">srcEncoding</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">destEncoding</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">EncodingError</span></span></tt> if it cannot fulfill the request.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/encodings.nim#L340" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/encodings.nim#L340" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="twelve-columns footer">
|
|
<span class="nim-sprite"></span>
|
|
<br>
|
|
<small style="color: var(--hint);">Made with Nim. Generated: 2025-09-27 04:01:57 UTC</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
|
|
|
|
</body>
|
|
</html>
|