Convert a UTF-8 string to a wide character string.
#include <ldap_utf8.h>
int ldap_x_utf8s_to_wcs (
wchar_t *wcstr,
const char *utf8str,
size_t count);
(OUT) Points to a wide char buffer to receive the converted wide char string. The output string will be null-terminated if there is space for it in the buffer.
(IN) Address of the null-terminated UTF-8 string to convert.
(IN) The number of UTF-8 characters to convert, or equivalently, the size of the output buffer in wide characters.
If successful, the function returns the number of wide characters written to wcstr, excluding the null termination character, if any.
If wcstr is NULL, the function returns the number of wide characters required to contain the converted string, excluding the null-termination character.
If an invalid UTF-8 sequence is encountered, the function returns -1.
If the return value equals count, there was not enough space to fit the string and the null terminator in the buffer. As much of the string as will fit is written to the buffer, but it is not null-terminated.
#define WCSTRLEN 10
char utstr_in[] = { 0xE2U, 0x98U, 0xA0U, ’a’, ’b’, ’c’, 0 };
wchar_t wcstr_out[WCSTRLEN];
int n;
/* Convert a UTF-8 string to a wide char string.
Returns wcstr_out = { 0x2620, ’a’, ’b’, ’c’, 0 }
Returns n = 4. ( # wide chars written, excl null )
If n==WCSTRLEN, the string could not completely fit in the given buffer.
*/
n = ldap_x_utf8s_to_wcs(wcstr_out, utstr_in, WCSTRLEN);