2019-02-04 22:26:45 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
2020-04-09 17:32:37 +00:00
< title > Wide Strings< / title >
2020-03-19 00:03:04 +00:00
< meta name = "viewport" content = "width=device-width initial-scale=1" >
2019-02-04 22:26:45 +00:00
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" >
< meta http-equiv = "Content-Language" content = "en-gb" >
2020-03-19 00:03:04 +00:00
< link href = "../inweb.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
2020-04-10 20:29:28 +00:00
2019-02-04 22:26:45 +00:00
< / head >
< body >
2020-03-19 00:03:04 +00:00
< 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" >
2020-04-09 17:32:37 +00:00
<!-- 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 >
2019-02-04 22:26:45 +00:00
< p class = "inwebparagraph" > < a id = "SP1" > < / a > < b > § 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" >
2020-04-06 11:26:10 +00:00
< 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 >
2019-02-04 22:26:45 +00:00
< 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" > § 2.3< / a > ).< / p >
< p class = "inwebparagraph" > < a id = "SP2" > < / a > < b > § 2. < / b > On the rare occasions when we need to sort alphabetically we'll also call:
< / p >
< pre class = "display" >
2020-04-06 11:26:10 +00:00
< 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 >
2019-02-04 22:26:45 +00:00
< 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" > § 21< / a > ).< / p >
< p class = "inwebparagraph" > < a id = "SP3" > < / a > < b > § 3. < / b > < / p >
< pre class = "display" >
2020-04-06 11:26:10 +00:00
< 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 >
2019-02-04 22:26:45 +00:00
< span class = "plain" > }< / span >
< / pre >
< p class = "inwebparagraph" > < / p >
< p class = "endnote" > The function Wide::atoi appears nowhere else.< / p >
2019-03-12 23:32:12 +00:00
< 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" >
2019-03-18 11:16:10 +00:00
<!-- End of weave -->
2020-03-19 00:03:04 +00:00
< / main >
2019-02-04 22:26:45 +00:00
< / body >
< / html >