diff options
Diffstat (limited to 'devdocs/c/string%2Fwide%2Fwcsxfrm.html')
| -rw-r--r-- | devdocs/c/string%2Fwide%2Fwcsxfrm.html | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fwide%2Fwcsxfrm.html b/devdocs/c/string%2Fwide%2Fwcsxfrm.html new file mode 100644 index 00000000..5ed66168 --- /dev/null +++ b/devdocs/c/string%2Fwide%2Fwcsxfrm.html @@ -0,0 +1,59 @@ + <h1 id="firstHeading" class="firstHeading">wcsxfrm</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 t-until-c99"> <td> <pre data-language="c">size_t wcsxfrm( wchar_t* dest, const wchar_t* src, size_t count );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-until-c99">(until C99)</span> <br><span class="t-mark-rev t-since-c95">(since C95)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">size_t wcsxfrm( wchar_t* restrict dest, const wchar_t* restrict src, size_t count );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <p>Transforms the null-terminated wide string pointed to by <code>src</code> into the implementation-defined form such that comparing two transformed strings with <code><a href="wcscmp" title="c/string/wide/wcscmp">wcscmp</a></code> gives the same result as comparing the original strings with <code><a href="wcscoll" title="c/string/wide/wcscoll">wcscoll</a></code>, in the current C locale.</p> +<p>The first <code>count</code> characters of the transformed string are written to destination, including the terminating null character, and the length of the full transformed string is returned, excluding the terminating null character.</p> +<p>If <code>count</code> is <code>0</code>, then <code>dest</code> is allowed to be a null pointer.</p> +<h3 id="Notes"> Notes</h3> <p>The correct length of the buffer that can receive the entire transformed string is <code><span class="nu0">1</span><span class="sy2">+</span>wcsxfrm<span class="br0">(</span><a href="http://en.cppreference.com/w/c/types/NULL"><span class="kw103">NULL</span></a>, src, <span class="nu0">0</span><span class="br0">)</span></code></p> +<p>This function is used when making multiple locale-dependent comparisons using the same wide string or set of wide strings, because it is more efficient to use <code>wcsxfrm</code> to transform all the strings just once, and subsequently compare the transformed wide strings with <code><a href="wcscmp" title="c/string/wide/wcscmp">wcscmp</a></code>.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> dest </td> <td> - </td> <td> pointer to the first element of a wide null-terminated string to write the transformed string to </td> +</tr> <tr class="t-par"> <td> src </td> <td> - </td> <td> pointer to the null-terminated wide character string to transform </td> +</tr> <tr class="t-par"> <td> count </td> <td> - </td> <td> maximum number of characters to output </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>The length of the transformed wide string, not including the terminating null-character.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> +#include <wchar.h> +#include <locale.h> + +int main(void) +{ + setlocale(LC_ALL, "sv_SE.utf8"); + + const wchar_t *in1 = L"\u00e5r"; + wchar_t out1[1+wcsxfrm(NULL, in1, 0)]; + wcsxfrm(out1, in1, sizeof out1/sizeof *out1); + + const wchar_t *in2 = L"\u00e4ngel"; + wchar_t out2[1+wcsxfrm(NULL, in2, 0)]; + wcsxfrm(out2, in2, sizeof out2/sizeof *out2); + + printf("In the Swedish locale: "); + if(wcscmp(out1, out2) < 0) + printf("%ls before %ls\n", in1, in2); + else + printf("%ls before %ls\n", in2, in1); + + printf("In lexicographical comparison: "); + if(wcscmp(in1, in2) < 0) + printf("%ls before %ls\n", in1, in2); + else + printf("%ls before %ls\n", in2, in1); +}</pre></div> <p>Output:</p> +<div class="text source-text"><pre data-language="c">In the Swedish locale: år before ängel +In lexicographical comparison: ängel before år</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.29.4.4.4 The wcsxfrm function (p: 434-435) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.24.4.4.4 The wcsxfrm function (p: 380-381) </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="../byte/strcoll" title="c/string/byte/strcoll"> <span class="t-lines"><span>strcoll</span></span></a></div> </td> <td> compares two strings in accordance to the current locale <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="wcscoll" title="c/string/wide/wcscoll"> <span class="t-lines"><span>wcscoll</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> compares two wide strings in accordance to the current locale <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="wcscmp" title="c/string/wide/wcscmp"> <span class="t-lines"><span>wcscmp</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> compares two wide strings <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="../byte/strxfrm" title="c/string/byte/strxfrm"> <span class="t-lines"><span>strxfrm</span></span></a></div> </td> <td> transform a string so that strcmp would produce the same result as strcoll <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/wide/wcsxfrm" title="cpp/string/wide/wcsxfrm">C++ documentation</a></span> for <code>wcsxfrm</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/wide/wcsxfrm" class="_attribution-link">https://en.cppreference.com/w/c/string/wide/wcsxfrm</a> + </p> +</div> |
