Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE char* U_EXPORT2 u_austrncpy ( char *  dst,
const UChar *  src,
int32_t  n 
)

Copy ustring to a byte string encoded in the default codepage. Copies at most n characters. The result will be null terminated if the length of src is less than n. Performs a UChar to host byte conversion

Parameters:
dst The destination string.
src The source string.
n The maximum number of characters to copy.
Returns:
A pointer to dst. ICU 2.0

Definition at line 178 of file ustr_cnv.c.

References NULL, TRUE, U_BUFFER_OVERFLOW_ERROR, U_FAILURE, U_SUCCESS, and U_ZERO_ERROR.

{
  char *target = s1;
  UErrorCode err = U_ZERO_ERROR;
  UConverter *cnv = u_getDefaultConverter(&err);
  if(U_SUCCESS(err) && cnv != NULL) {
    ucnv_reset(cnv);
    ucnv_fromUnicode(cnv,
                  &target,
                  s1+n,
                  &ucs2,
                  ucs2+u_ustrnlen(ucs2, n),
                  NULL,
                  TRUE,
                  &err);
    ucnv_reset(cnv); /* be good citizens */
    u_releaseDefaultConverter(cnv);
    if(U_FAILURE(err) && (err != U_BUFFER_OVERFLOW_ERROR) ) {
      *s1 = 0; /* failure */
    }
    if(target < (s1+n)) { /* U_BUFFER_OVERFLOW_ERROR isn't an err, just means no termination will happen. */
      *target = 0;  /* terminate */
    }
  } else {
    *s1 = 0;
  }
  return s1;
}


Generated by  Doxygen 1.6.0   Back to index