ldap_x_wc_to_utf8

Convert a single wide character to a UTF-8 sequence.

Library:*ldapsdk.*
Platform:NLM, Windows (NT, 95, 98, 2000, XP, Vista 32-bit and 64-bit ), Linux (32-bit and 64-bit), Solaris, AIX, and HP-UX

Syntax

  #include <ldap_utf8.h>
  
  int ldap_x_wc_to_utf8 (
     char    *utf8char,
     wchar_t  wchar,
     size_t   count);
  

Parameters

utf8char

(OUT) Points to a byte array to receive the converted UTF-8 string.

wchar

(IN) The wide character to be converted.

count

(IN) The maximum number of bytes to write to the output buffer. Normally set this to LDAP_MAX_UTF8_LEN, which is defined as 3 or 6 depending on the size of wchar_t. A partial character will not be written.

Return Values

If successful, the function returns the length in bytes of the converted UTF-8 output character.

If wchar is NULL, the function returns 1 and 0 is written to utf8char.

If wchar cannot be converted to a UTF-8 character, the function returns -1.

If the converted character will not fit in count bytes, 0 is returned.

Example

  wchar_t wc_in = 0x2620;
  char utchr_out[LDAP_MAX_UTF8_LEN];       /* Either 3 or 6 bytes */
  int n;
  
  /* Convert a wide character to a UTF-8 character.
     Returns utchr_out[] = { 0xE2, 0x98, 0xA0 }
     Returns n = 3.  (Byte length of utchr_out)
  */
  n = ldap_x_wc_to_utf8(utchr_out, wc_in, LDAP_MAX_UTF8_LEN);