diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/string%2Fmultibyte%2Fwctob.html | |
new repository
Diffstat (limited to 'devdocs/c/string%2Fmultibyte%2Fwctob.html')
| -rw-r--r-- | devdocs/c/string%2Fmultibyte%2Fwctob.html | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fmultibyte%2Fwctob.html b/devdocs/c/string%2Fmultibyte%2Fwctob.html new file mode 100644 index 00000000..c942d365 --- /dev/null +++ b/devdocs/c/string%2Fmultibyte%2Fwctob.html @@ -0,0 +1,54 @@ + <h1 id="firstHeading" class="firstHeading">wctob</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><wchar.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td> <pre data-language="c">int wctob( wint_t c );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c95">(since C95)</span> </td> </tr> </table> <p>Narrows a wide character <code>c</code> if its multibyte character equivalent in the initial shift state is a single byte.</p> +<p>This is typically possible for the characters from the ASCII character set, since most multibyte encodings (such as UTF-8) use single bytes to encode those characters.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> c </td> <td> - </td> <td> wide character to narrow </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p><code><a href="../../io" title="c/io">EOF</a></code> if <code>c</code> does not represent a multibyte character with length <code>1</code> in initial shift state.</p> +<p>otherwise, the single-byte representation of <code>c</code> as <code>unsigned char</code> converted to <code>int</code></p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <locale.h> +#include <wchar.h> +#include <stdio.h> +#include <assert.h> + +void try_narrowing(wchar_t c) +{ + int cn = wctob(c); + if(cn != EOF) + printf("%#x narrowed to %#x\n", c, cn); + else + printf("%#x could not be narrowed\n", c); +} + +int main(void) +{ + char* utf_locale_present = setlocale(LC_ALL, "th_TH.utf8"); + assert(utf_locale_present); + puts("In Thai UTF-8 locale:"); + try_narrowing(L'a'); + try_narrowing(L'๛'); + + char* tis_locale_present = setlocale(LC_ALL, "th_TH.tis620"); + assert(tis_locale_present); + puts("In Thai TIS-620 locale:"); + try_narrowing(L'a'); + try_narrowing(L'๛'); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">In Thai UTF-8 locale: +0x61 narrowed to 0x61 +0xe5b could not be narrowed +In Thai TIS-620 locale: +0x61 narrowed to 0x61 +0xe5b narrowed to 0xfb</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.29.6.1.2 The wctob function (p: 441) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.24.6.1.2 The wctob function (p: 387) </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="btowc" title="c/string/multibyte/btowc"> <span class="t-lines"><span>btowc</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c95">(C95)</span></span></span></div> </td> <td> widens a single-byte narrow character to wide character, if possible <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/string/multibyte/wctob" title="cpp/string/multibyte/wctob">C++ documentation</a></span> for <code>wctob</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/string/multibyte/wctob" class="_attribution-link">https://en.cppreference.com/w/c/string/multibyte/wctob</a> + </p> +</div> |
