Append the operand string to the contents of this.
| Return Type | Function name | Arguments |
|---|---|---|
| hzString& | hzString::operator+= | (hzString&,) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::operator+= (hzString& op)
{
// Append the operand string to the contents of this.
//
// Argument: op Operand string
// Returns: Reference to this string in all cases
_hzfunc("hzString::op+=(hzString&)") ;
_strItem* thisCtl = 0; // This string control area
_strItem* suppCtl ; // Supplied string control area
_strItem* destCtl ; // Result string space
char* tgt ; // Target data area
uint32_t destAddr ; // New string address if required
uint32_t crlen ; // Len of this string
uint32_t nulen ; // Len of combined string
// If operand is empty do nothing
if (!op.m_addr)
return *this ;
suppCtl = _strXlate(op.m_addr) ;
crlen = 0;
if (m_addr)
{
thisCtl = _strXlate(m_addr) ;
crlen = thisCtl->_getSize() ;
}
// Calculate required length
nulen = Length() + op.Length() ;
// Allocate and populate a new buffer
destAddr = _strAlloc(nulen) ;
destCtl = _strXlate(destAddr) ;
destCtl->_setSize(nulen) ;
tgt = destCtl->_data() ;
if (crlen)
memcpy(tgt, thisCtl->_data(), crlen) ;
memcpy(tgt + crlen, suppCtl->_data(), suppCtl->_getSize()) ;
tgt[nulen] = 0;
destCtl->m_copy = 1;
// Tidy up
if (thisCtl && thisCtl->m_copy && thisCtl->m_copy < 50)
{
if (!_hzGlobal_MT)
{
thisCtl->m_copy-- ;
if (!thisCtl->m_copy)
_strFree(m_addr, thisCtl->_getSize()) ;
}
else
{
if (__sync_add_and_fetch(&(thisCtl->m_copy), -1)== 0)
_strFree(m_addr, thisCtl->_getSize()) ;
}
}
m_addr = destAddr ;
return *this ;
}