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

UnicodeString & UnicodeString::setTo ( UChar *  buffer,
int32_t  buffLength,
int32_t  buffCapacity 

Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor. The text will be used for the UnicodeString object, but it will not be released when the UnicodeString is destroyed. This has write-through semantics: For as long as the capacity of the buffer is sufficient, write operations will directly affect the buffer. When more capacity is necessary, then a new buffer will be allocated and the contents copied as with regularly constructed strings. In an assignment to another UnicodeString, the buffer will be copied. The extract(UChar *dst) function detects whether the dst pointer is the same as the string buffer itself and will in this case not copy the contents.

buffer The characters to alias for the UnicodeString.
buffLength The number of Unicode characters in buffer to alias.
buffCapacity The size of buffer in UChars.
a reference to this ICU 2.0

Definition at line 1125 of file unistr.cpp.

References NULL, and setToBogus().

  if(fFlags & kOpenGetBuffer) {
    // do not modify a string that has an "open" getBuffer(minCapacity)
    return *this;

  if(buffer == NULL) {
    // treat as an empty string, do not alias
    return *this;

  if(buffLength < -1 || buffCapacity < 0 || buffLength > buffCapacity) {
    return *this;
  } else if(buffLength == -1) {
    // buffLength = u_strlen(buff); but do not look beyond buffCapacity
    const UChar *p = buffer, *limit = buffer + buffCapacity;
    while(p != limit && *p != 0) {
    buffLength = (int32_t)(p - buffer);


  setArray(buffer, buffLength, buffCapacity);
  fFlags = kWritableAlias;
  return *this;

Generated by  Doxygen 1.6.0   Back to index