/// Appends another UTF8 string. REMutableString & REMutableString::append(const char * utf8String, const REUInt32 utf8StringLength) { const REUInt32 len = REStringUtilsPrivate::actualUTF8StringLength(utf8String, utf8StringLength); if (len) { const REUInt32 thisLen = this->length(); const REUInt32 newLen = len + thisLen; REBuffer * newBuffer = new REBuffer(); if (newBuffer) { if (newBuffer->resize(newLen + 1, false)) { char * newData = (char *)newBuffer->buffer(); if (thisLen > 0) { memcpy(newData, this->UTF8String(), thisLen); } memcpy(&newData[thisLen], utf8String, len); newData[newLen] = 0; _p = REPtr<REBuffer>(newBuffer); return (*this); } delete newBuffer; } } return (*this); }
void REMutableString::replaceWithLen(const char * charsStringValue, const char * withCharsStringValue, const REUInt32 firstLen, const REUInt32 secondLen) { if (firstLen) { const REUInt32 length = this->length(); REUInt32 ocurencesCount = 0; char * mainString = (char *)_p->buffer(); while ( (mainString = strstr(mainString, charsStringValue)) ) { ocurencesCount++; mainString += firstLen; } if (ocurencesCount) { const REUInt32 resultLen = (length + (ocurencesCount * secondLen)) - (ocurencesCount * firstLen); REBuffer * newBuffer = new REBuffer(); if (!newBuffer) return; if (!newBuffer->resize(resultLen + 1, false)) return; char * newData = (char *)newBuffer->buffer(); mainString = (char *)_p->buffer(); char * srcString = (char *)_p->buffer(); char * dstString = newData; while ( (mainString = strstr(mainString, charsStringValue)) ) { while (srcString != mainString) { *dstString++ = *srcString++; } REUByte * addString = (REUByte *)withCharsStringValue; REUInt32 addLen = secondLen; while (addLen) { *dstString++ = *addString++; addLen--; } mainString += firstLen; srcString += firstLen; } while (*srcString) { *dstString++ = *srcString++; } newData[resultLen] = 0; _p = REPtr<REBuffer>(newBuffer); } } }