Logo Search packages:      
Sourcecode: icu version File versions

UnicodeString & UnicodeString::setTo ( UBool  isTerminated,
const UChar *  text,
int32_t  textLength 

Aliasing setTo() function, analogous to the readonly-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 copy-on-write semantics: When the string is modified, then the buffer is first copied into newly allocated memory. The aliased buffer is never modified. In an assignment to another UnicodeString, the text will be aliased again, so that both strings then alias the same readonly-text.

isTerminated specifies if text is NUL-terminated. This must be true if textLength==-1.
text The characters to alias for the UnicodeString.
textLength The number of Unicode characters in text to alias. If -1, then this constructor will determine the length by calling u_strlen().
a reference to this ICU 2.0

Definition at line 1075 of file unistr.cpp.

References NULL, setToBogus(), and u_strlen().

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

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

  if( textLength < -1 ||
      (textLength == -1 && !isTerminated) ||
      (textLength >= 0 && isTerminated && text[textLength] != 0)
  ) {
    return *this;


  if(textLength == -1) {
    // text is terminated, or else it would have failed the above test
    textLength = u_strlen(text);
  setArray((UChar *)text, textLength, isTerminated ? textLength + 1 : textLength);

  fFlags = kReadonlyAlias;
  return *this;

Generated by  Doxygen 1.6.0   Back to index