1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<h1 id="firstHeading" class="firstHeading">mbrtoc8</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><uchar.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">size_t mbrtoc8( char8_t * restrict pc8, const char * restrict s,
size_t n, mbstate_t * restrict ps );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> </table> <p>Converts a narrow multibyte character to UTF-8 encoding.</p>
<p>If <code>s</code> is not a null pointer, inspects at most <code>n</code> bytes of the multibyte character string, beginning with the byte pointed to by <code>s</code> to determine the number of bytes necessary to complete the next multibyte character (including any shift sequences). If the function determines that the next multibyte character in <code>s</code> is complete and valid, converts it to UTF-8 and stores the first UTF-8 code unit in <code>*pc8</code> (if <code>pc8</code> is not null).</p>
<p>If UTF-8 encoding of the multibyte character in <code>*s</code> consists of more than one UTF-8 code unit, then after the first call to this function, <code>*ps</code> is updated in such a way that the next call to <code>mbrtoc8</code> will write out the additional UTF-8 code units, without considering <code>*s</code>.</p>
<p>If <code>s</code> is a null pointer, the values of <code>n</code> and <code>pc8</code> are ignored and the call is equivalent to <code>mbrtoc8(nullptr, "", 1, ps)</code>.</p>
<p>If UTF-8 code unit produced is <code>u8'\0'</code>, the conversion state <code>*ps</code> represents the initial shift state.</p>
<p>The multibyte 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> pc8 </td> <td> - </td> <td> pointer to the location where the resulting UTF-8 code units will be written </td>
</tr> <tr class="t-par"> <td> s </td> <td> - </td> <td> pointer to the multibyte character string used as input </td>
</tr> <tr class="t-par"> <td> n </td> <td> - </td> <td> limit on the number of bytes in s that can be examined </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>The first of the following that applies:</p>
<ul>
<li> <code>0</code> if the character converted from <code>s</code> (and stored in <code>*pc8</code> if non-null) was the null character </li>
<li> the number of bytes <code>[1...n]</code> of the multibyte character successfully converted from <code>s</code> </li>
<li> <code><span class="br0">(</span><a href="http://en.cppreference.com/w/c/types/size_t"><span class="kw100">size_t</span></a><span class="br0">)</span><span class="sy2">-</span><span class="nu0">3</span></code> if the next UTF-8 code unit from a character whose encoding consists of multiple code units has now been written to <code>*pc8</code>. No bytes are processed from the input in this case. </li>
<li> <code><span class="br0">(</span><a href="http://en.cppreference.com/w/c/types/size_t"><span class="kw100">size_t</span></a><span class="br0">)</span><span class="sy2">-</span><span class="nu0">2</span></code> if the next <code>n</code> bytes constitute an incomplete, but so far valid, multibyte character. Nothing is written to <code>*pc8</code>. </li>
<li> <code><span class="br0">(</span><a href="http://en.cppreference.com/w/c/types/size_t"><span class="kw100">size_t</span></a><span class="br0">)</span><span class="sy2">-</span><span class="nu0">1</span></code> if encoding error occurs. Nothing is written to <code>*pc8</code>, the value <code><a href="../../error/errno_macros" title="c/error/errno macros">EILSEQ</a></code> is stored in <code><a href="../../error/errno" title="c/error/errno">errno</a></code> and the value of <code>*ps</code> is unspecified. </li>
</ul> <h3 id="Example"> Example</h3> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="c8rtomb" title="c/string/multibyte/c8rtomb"> <span class="t-lines"><span>c8rtomb</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> converts UTF-8 string to narrow multibyte encoding <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/mbrtoc8" title="cpp/string/multibyte/mbrtoc8">C++ documentation</a></span> for <code>mbrtoc8</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/mbrtoc8" class="_attribution-link">https://en.cppreference.com/w/c/string/multibyte/mbrtoc8</a>
</p>
</div>
|