summaryrefslogtreecommitdiff
path: root/devdocs/c/string%2Fmultibyte%2Fc32rtomb.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/string%2Fmultibyte%2Fc32rtomb.html
new repository
Diffstat (limited to 'devdocs/c/string%2Fmultibyte%2Fc32rtomb.html')
-rw-r--r--devdocs/c/string%2Fmultibyte%2Fc32rtomb.html60
1 files changed, 60 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fmultibyte%2Fc32rtomb.html b/devdocs/c/string%2Fmultibyte%2Fc32rtomb.html
new file mode 100644
index 00000000..c6b285c5
--- /dev/null
+++ b/devdocs/c/string%2Fmultibyte%2Fc32rtomb.html
@@ -0,0 +1,60 @@
+ <h1 id="firstHeading" class="firstHeading">c32rtomb</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;uchar.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c11"> <td> <pre data-language="c">size_t c32rtomb( char* restrict s, char32_t c32, mbstate_t* restrict ps );</pre>
+</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <p>Converts a single code point from its variable-length 32-bit wide character representation (but typically, UTF-32) to its narrow multibyte character representation.</p>
+<p>If <code>s</code> is not a null pointer, the function determines the number of bytes necessary to store the multibyte character representation of <code>c32</code> (including any shift sequences, and taking into account the current multibyte conversion state <code>*ps</code>), and stores the multibyte character representation in the character array whose first element is pointed to by <code>s</code>, updating <code>*ps</code> as necessary. At most <code>MB_CUR_MAX</code> bytes can be written by this function.</p>
+<p>If <code>s</code> is a null pointer, the call is equivalent to <code>c32rtomb(buf, U'\0', ps)</code> for some internal buffer <code>buf</code>.</p>
+<p>If <code>c32</code> is the null wide character <code>U'\0'</code>, a null byte is stored, preceded by any shift sequence necessary to restore the initial shift state and the conversion state parameter <code>*ps</code> is updated to represent the initial shift state.</p>
+<p>If the macro <code>__STDC_UTF_32__</code> is defined, the 32-bit encoding used by this function is UTF-32; otherwise, it is implementation-defined. <span class="t-rev-inl t-since-c23"><span>The macro is always defined and the encoding is always UTF-32.</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> In any case, the multibyte character encoding used by this function is specified by the currently active C locale.</p>
+<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> s </td> <td> - </td> <td> pointer to narrow character array where the multibyte character will be stored </td>
+</tr> <tr class="t-par"> <td> c32 </td> <td> - </td> <td> the 32-bit wide character to convert </td>
+</tr> <tr class="t-par"> <td> ps </td> <td> - </td> <td> pointer to the conversion state object used when interpreting the multibyte string </td>
+</tr>
+</table> <h3 id="Return_value"> Return value</h3> <p>On success, returns the number of bytes (including any shift sequences) written to the character array whose first element is pointed to by <code>s</code>. This value may be <code>​0​</code>, e.g. when processing the leading <code>char32_t</code> units in a multi-<code>char32_t</code>-unit sequence (does not occur in UTF-32).</p>
+<p>On failure (if <code>c32</code> is not a valid 32-bit wide character), returns <code>-1</code>, stores <code><a href="../../error/errno_macros" title="c/error/errno macros">EILSEQ</a></code> in <code><a href="../../error/errno" title="c/error/errno">errno</a></code>, and leaves <code>*ps</code> in unspecified state.</p>
+<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;locale.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;uchar.h&gt;
+
+mbstate_t state;
+
+int main(void)
+{
+ setlocale(LC_ALL, "en_US.utf8");
+ const char32_t in[] = U"zß水🍌"; // or "z\u00df\u6c34\U0001F34C"
+ size_t in_sz = sizeof in / sizeof *in;
+
+ printf("Processing %zu UTF-32 code units: [ ", in_sz);
+ for (size_t n = 0; n &lt; in_sz; ++n)
+ printf("%#x ", in[n]);
+ puts("]");
+
+ char out[MB_CUR_MAX * in_sz];
+ char* p = out;
+ for (size_t n = 0; n &lt; in_sz; ++n)
+ {
+ size_t rc = c32rtomb(p, in[n], &amp;state);
+ if(rc == (size_t)-1) break;
+ p += rc;
+ }
+
+ size_t out_sz = p - out;
+ printf("into %zu UTF-8 code units: [ ", out_sz);
+ for (size_t x = 0; x &lt; out_sz; ++x)
+ printf("%#x ", +(unsigned char)out[x]);
+ puts("]");
+}</pre></div> <p>Output:</p>
+<div class="text source-text"><pre data-language="c">Processing 5 UTF-32 code units: [ 0x7a 0xdf 0x6c34 0x1f34c 0 ]
+into 11 UTF-8 code units: [ 0x7a 0xc3 0x9f 0xe6 0xb0 0xb4 0xf0 0x9f 0x8d 0x8c 0 ]</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C23 standard (ISO/IEC 9899:2023): </li>
+<ul><li> 7.30.1.6 The c32rtomb function (p: 411) </li></ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 7.28.1.4 The c32rtomb function (p: 401) </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="mbrtoc32" title="c/string/multibyte/mbrtoc32"> <span class="t-lines"><span>mbrtoc32</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> generates the next 32-bit wide character from a narrow multibyte string <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/c32rtomb" title="cpp/string/multibyte/c32rtomb">C++ documentation</a></span> for <code>c32rtomb</code> </td>
+</tr> </table> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 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/c32rtomb" class="_attribution-link">https://en.cppreference.com/w/c/string/multibyte/c32rtomb</a>
+ </p>
+</div>