wchar_t *restrict dst, rsize_t dstsz,
const char **restrict src, rsize_t len,
Converts a null-terminated multibyte character sequence, which begins in the conversion state described by
*ps
, from the array whose first element is pointed to by
*srcto its wide character representation. If
dst
is not null, converted characters are stored in the successive elements of the wchar_t array pointed to by
dst
. No more than
len
wide characters are written to the destination array. Each multibyte character is converted as if by a call to
mbrtowc. The conversion stops if:
*ps
represents the initial shift state.len
. *src is set to point at the beginning of the first unconverted multibyte character. This condition is not checked if dst
is a null pointer.Same as
(1), except that
retval
dst
after len
wide characters were written, then L'\0' is stored in dst[len]
, which means len+1 total wide characters are writtendstsz
src
and dst
overlap, the behavior is unspecified.retval
, ps
, src
, or *src is a null pointerdstsz
or len
is greater than RSIZE_MAX/sizeof(wchar_t) (unless dst
is null)dstsz
is not zero (unless dst
is null)dstsz
multibyte characters in the *src array and len
is greater than dstsz
(unless dst
is null)mbsrtowcs_s
is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including <wchar.h>.
dst
array) retval - pointer to a size_t object where the result will be stored [edit] Return value 1)
On success, returns the number of wide characters, excluding the terminating
L'\0', written to the character array. If
dst
is a null pointer, returns the number of wide characters that would have been written given unlimited length. On conversion error (if invalid multibyte character was encountered), returns
(size_t)-1, stores
EILSEQin
errno, and leaves
*psin unspecified state.
2)zero on success (in which case the number of wide characters excluding terminating zero that were, or would be written to
dst
, is stored in
*retval), non-sero on error. In case of a runtime constraint violation, stores
(size_t)-1in
*retval(unless
retval
is null) and sets
dst[0]to
L'\0'(unless
dst
is null or
dstmax
is zero or greater than
RSIZE_MAX)
[edit] Example#include <stdio.h> #include <locale.h> #include <wchar.h> #include <string.h> void print_as_wide(const char* mbstr) { mbstate_t state; memset(&state, 0, sizeof state); size_t len = 1 + mbsrtowcs(NULL, &mbstr, 0, &state); wchar_t wstr[len]; mbsrtowcs(&wstr[0], &mbstr, len, &state); wprintf(L"Wide string: %ls \n", wstr); wprintf(L"The length, including L'\\0': %zu\n", len); } int main(void) { setlocale(LC_ALL, "en_US.utf8"); print_as_wide(u8"z\u00df\u6c34\U0001f34c"); // u8"zÃæ°´ð" }
Output:
Wide string: zÃæ°´ð The length, including L'\0': 5[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4