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

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

Copy a byte string encoded in the default codepage to a ustring. Copies at most n characters. The result will be null terminated if the length of src is less than n. Performs a host byte to UChar 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 106 of file ustr_cnv.c.

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

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


Generated by  Doxygen 1.6.0   Back to index