Truncate the string

Return TypeFunction nameArguments
hzString&hzString::Truncate(uint32_t,)

Declared in file: hzString.h
Defined in file : hzString.cpp

Function Logic:

0:START 1:unknown 2:Return *this 3:thisCtl 4:unknown 5:Return *this 6:unknown 7:destAddr destCtl items items destCtl 8:unknown 9:unknown 10:items 11:unknown 12:items 13:unknown 14:items 15:m_addr 16:Return *this

Function body:

hzString& hzString::Truncate (uint32_t limit)
{
   //  Truncate the string
   //  
   //  Arguments: 1) limit Sets max length for the string and truncates beyond this.
   //  Returns: Reference to this string in all cases
   _hzfunc("hzString::Truncate") ;
   _strItem*   thisCtl ;       //  This string's control area
   _strItem*   destCtl ;       //  New control area
   uint32_t    destAddr = 0;   //  New string address if required
   //  If NULL return
   if (!m_addr)
       return *this ;
   thisCtl = _strXlate(m_addr) ;
   //  Do nothing if the size limit exceeds length of string value
   if (limit >&eq; thisCtl->_getSize())
       return *this ;
   //  Full truncation, delete
   if (limit)
   {
       //  Perform the (partial) truncation
       destAddr = _strAlloc(limit) ;
       destCtl = _strXlate(destAddr) ;
       destCtl->_setSize(limit) ;
       memcpy(destCtl->_data(), thisCtl->_data(), limit) ;
       destCtl->m_copy = 1;
   }
   //  Tidy up
   if (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 ;
}