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

UnicodeString UnicodeString::fromUTF32 ( const UChar32 utf32,
int32_t  length 
) [static]

Create a UnicodeString from a UTF-32 string. Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string. Calls u_strFromUTF32WithSub().

utf32UTF-32 input string. Must not be NULL.
lengthLength of the input string, or -1 if NUL-terminated.
A UnicodeString with equivalent UTF-16 contents.
See also:
toUTF32 ICU 4.2

Definition at line 414 of file unistr.cpp.

References getBuffer(), getCapacity(), length(), NULL, releaseBuffer(), setToBogus(), TRUE, U_BUFFER_OVERFLOW_ERROR, U_FAILURE, and U_ZERO_ERROR.

  UnicodeString result;
  int32_t capacity;
  // Most UTF-32 strings will be BMP-only and result in a same-length
  // UTF-16 string. We overestimate the capacity just slightly,
  // just in case there are a few supplementary characters.
  if(length <= US_STACKBUF_SIZE) {
    capacity = US_STACKBUF_SIZE;
  } else {
    capacity = length + (length >> 4) + 4;
  do {
    UChar *utf16 = result.getBuffer(capacity);
    int32_t length16;
    UErrorCode errorCode = U_ZERO_ERROR;
    u_strFromUTF32WithSub(utf16, result.getCapacity(), &length16,
        utf32, length,
        0xfffd,  // Substitution character.
        NULL,    // Don't care about number of substitutions.
    if(errorCode == U_BUFFER_OVERFLOW_ERROR) {
      capacity = length16 + 1;  // +1 for the terminating NUL.
    } else if(U_FAILURE(errorCode)) {
  } while(TRUE);
  return result;

Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index