Logo Search packages:      
Sourcecode: icu version File versions

UnicodeString & UnicodeString::findAndReplace ( int32_t  start,
int32_t  length,
const UnicodeString oldText,
int32_t  oldStart,
int32_t  oldLength,
const UnicodeString newText,
int32_t  newStart,
int32_t  newLength 

Replace all occurrences of characters in oldText in the range [oldStart, oldStart + oldLength) with the characters in newText in the range [newStart, newStart + newLength) in the range [start, start + length).

start the start of the range in which replace will performed
length the length of the range in which replace will be performed
oldText the text containing the search text
oldStart the start of the search range in oldText
oldLength the length of the search range in oldText
newText the text containing the replacement text
newStart the start of the replacement range in newText
newLength the length of the replacement range in newText
a reference to this ICU 2.0

Definition at line 1016 of file unistr.cpp.

References indexOf(), isBogus(), pinIndices(), and replace().

  if(isBogus() || oldText.isBogus() || newText.isBogus()) {
    return *this;

  pinIndices(start, length);
  oldText.pinIndices(oldStart, oldLength);
  newText.pinIndices(newStart, newLength);

  if(oldLength == 0) {
    return *this;

  while(length > 0 && length >= oldLength) {
    int32_t pos = indexOf(oldText, oldStart, oldLength, start, length);
    if(pos < 0) {
      // no more oldText's here: done
    } else {
      // we found oldText, replace it by newText and go beyond it
      replace(pos, oldLength, newText, newStart, newLength);
      length -= pos + oldLength - start;
      start = pos + newLength;

  return *this;

Generated by  Doxygen 1.6.0   Back to index