inweb-bootstrap/docs/foundation-module/4-ws.html
2020-04-09 18:32:37 +01:00

80 lines
4.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Wide Strings</title>
<meta name="viewport" content="width=device-width initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="en-gb">
<link href="../inweb.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>
<body>
<nav role="navigation">
<h1><a href="../webs.html">Sources</a></h1>
<ul>
<li><a href="../inweb/index.html">inweb</a></li>
</ul>
<h2>Foundation</h2>
<ul>
<li><a href="../foundation-module/index.html">foundation-module</a></li>
<li><a href="../foundation-test/index.html">foundation-test</a></li>
</ul>
</nav>
<main role="main">
<!--Weave of 'Wide Strings' generated by 7-->
<ul class="crumbs"><li><a href="../webs.html">Source</a></li><li><a href="index.html">foundation</a></li><li><a href="index.html#4">Chapter 4: Text Handling</a></li><li><b>Wide Strings</b></li></ul><p class="purpose">A minimal library for handling wide C strings.</p>
<p class="inwebparagraph"><a id="SP1"></a><b>&#167;1. </b>By "wide string", we mean an array of <code class="display"><span class="extract">wchar_t</span></code>. A pointer to this type
is what is returned by an L-literal in ANSI C, such as <code class="display"><span class="extract">L"look, I'm wide"</span></code>.
A wide string is essentially a C string but with characters stored in full
words instead of bytes. The character values should be Unicode code points.
</p>
<p class="inwebparagraph">We will do as little as possible with wide strings, and the following
wrappers simply abstract the standard C library's handling.
</p>
<pre class="display">
<span class="reserved">int</span><span class="plain"> </span><span class="functiontext">Wide::len</span><span class="plain">(</span><span class="identifier">wchar_t</span><span class="plain"> *</span><span class="identifier">p</span><span class="plain">) {</span>
<span class="reserved">return</span><span class="plain"> (</span><span class="reserved">int</span><span class="plain">) </span><span class="identifier">wcslen</span><span class="plain">(</span><span class="identifier">p</span><span class="plain">);</span>
<span class="plain">}</span>
</pre>
<p class="inwebparagraph"></p>
<p class="endnote">The function Wide::len is used in 4/taa (<a href="4-taa.html#SP2_3">&#167;2.3</a>).</p>
<p class="inwebparagraph"><a id="SP2"></a><b>&#167;2. </b>On the rare occasions when we need to sort alphabetically we'll also call:
</p>
<pre class="display">
<span class="reserved">int</span><span class="plain"> </span><span class="functiontext">Wide::cmp</span><span class="plain">(</span><span class="identifier">wchar_t</span><span class="plain"> *</span><span class="identifier">A</span><span class="plain">, </span><span class="identifier">wchar_t</span><span class="plain"> *</span><span class="identifier">B</span><span class="plain">) {</span>
<span class="reserved">return</span><span class="plain"> </span><span class="identifier">wcscmp</span><span class="plain">(</span><span class="identifier">A</span><span class="plain">, </span><span class="identifier">B</span><span class="plain">);</span>
<span class="plain">}</span>
</pre>
<p class="inwebparagraph"></p>
<p class="endnote">The function Wide::cmp is used in 5/htm (<a href="5-htm.html#SP21">&#167;21</a>).</p>
<p class="inwebparagraph"><a id="SP3"></a><b>&#167;3. </b></p>
<pre class="display">
<span class="reserved">int</span><span class="plain"> </span><span class="functiontext">Wide::atoi</span><span class="plain">(</span><span class="identifier">wchar_t</span><span class="plain"> *</span><span class="identifier">p</span><span class="plain">) {</span>
<span class="reserved">return</span><span class="plain"> (</span><span class="reserved">int</span><span class="plain">) </span><span class="identifier">wcstol</span><span class="plain">(</span><span class="identifier">p</span><span class="plain">, </span><span class="identifier">NULL</span><span class="plain">, </span><span class="constant">10</span><span class="plain">);</span>
<span class="plain">}</span>
</pre>
<p class="inwebparagraph"></p>
<p class="endnote">The function Wide::atoi appears nowhere else.</p>
<hr class="tocbar">
<ul class="toc"><li><a href="4-cst.html">Back to 'C Strings'</a></li><li><a href="4-sm.html">Continue with 'String Manipulation'</a></li></ul><hr class="tocbar">
<!--End of weave-->
</main>
</body>
</html>