Reverse the string content. This first ensures the string is independent. Arguments: None
| Return Type | Function name | Arguments |
|---|---|---|
| hzString& | hzString::Reverse | (void) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::Reverse (void)
{
// Reverse the string content. This first ensures the string is independent.
//
// Arguments: None
// Returns: Reference to this string in all cases
_hzfunc("hzString::Reverse") ;
_strItem* thisCtl ; // This string's control area
_strItem* destCtl ; // New internal structure if required
char* pTgt ; // Target internal value
char* pSrc ; // Source internal value
uint32_t destAddr ; // New string address if required
uint32_t nLen ; // Length
uint32_t c_up ; // Ascending iterator
uint32_t c_down ; // Decending iterator
// If NULL return
if (!m_addr)
return *this ;
thisCtl = _strXlate(m_addr) ;
// Allocate new space
nLen = thisCtl->_getSize() ;
destAddr = _strAlloc(nLen) ;
destCtl = _strXlate(destAddr) ;
destCtl->_setSize(nLen) ;
destCtl->m_copy = 1;
// Create new string value as the reverse of the original
c_down = nLen - 1;
pSrc = thisCtl->_data() ;
pTgt = destCtl->_data() ;
for (c_up = 0; c_up < c_down ; c_up++, c_down--)
{
pTgt[c_up] = pSrc[c_down] ;
}
// 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 ;
}