Conditional, content based truncation. If the supplied patern exists in the string, the new string will be everything beyond but not including the first instance of the patern. If the pattern is empty or does not exist in the string, the string content will be unchanged.

Return TypeFunction nameArguments
hzString&hzString::TruncateBeyond(const char*,)

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

Function Logic:

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

Function body:

hzString& hzString::TruncateBeyond (const char* patern)
{
   //  Category: Text Processing
   //  
   //  Conditional, content based truncation. If the supplied patern exists in the string, the new string will be everything beyond but not including the first
   //  instance of the patern. If the pattern is empty or does not exist in the string, the string content will be unchanged.
   //  
   //  Arguments: 1) pattern The pattern at which the string will be truncated.
   //  Returns: Reference to this string in all cases
   _hzfunc("hzString::TruncateBeyond") ;
   _strItem*       thisCtl ;       //  This string's control area
   _strItem*       destCtl ;       //  New control area
   char*           i ;             //  Pointer into old string data
   char*           j ;             //  Pointer into new string data
   uint32_t        destAddr ;      //  New string address if required
   uint32_t        newLen ;        //  New string length
   //  If no pattern supplied, do nothing
   if (!patern || !patern[0])
       return *this ;
   //  If NULL return
   if (!m_addr)
       return *this ;
   //  Test if change required
   thisCtl = _strXlate(m_addr) ;
   i = strstr((char*) thisCtl->_data(), patern) ;
   if (!i)
       return *this ;
   //  Allocate new space
   newLen = i - thisCtl->_data() ;
   destAddr = _strAlloc(newLen) ;
   destCtl = _strXlate(destAddr) ;
   destCtl->_setSize(newLen) ;
   destCtl->m_copy = 1;
   i += strlen(patern) ;
   for (j = destCtl->_data() ; *i ; *j++ = *i++) ;
   *j = 0;
   //  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 ;
}