Removes leading whitespace from the string Arguments: None
| Return Type | Function name | Arguments |
|---|---|---|
| hzString& | hzString::DelWhiteLead | (void) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::DelWhiteLead (void)
{
// Removes leading whitespace from the string
//
// Arguments: None
// Returns: Reference to this string in all cases
_hzfunc("hzString::DelWhiteLead") ;
_strItem* thisCtl ; // This string's control area
_strItem* destCtl ; // New string space
const char* i ; // Pointer into string data
uint32_t destAddr ; // New string address if required
uint32_t wc ; // Count of whitespace chars
uint32_t count ; // Iterator
uint32_t nLen ; // Length of original string
uint32_t nusize ; // The size the string will be once leading whitespace removed
// If NULL return
if (!m_addr)
return *this ;
// Check that change is needed
thisCtl = _strXlate(m_addr) ;
nLen = Length() ;
i = (char*) thisCtl->_data() ;
for (wc = count = 0; count < nLen ; count++)
{
if (i[count] <&eq; CHAR_SPACE)
wc++ ;
else
break ;
}
if (!wc)
return *this ;
// Must alter content
nusize = nLen - wc ;
if (nusize <&eq; 0)
{
Clear() ;
return *this ;
}
destAddr = _strAlloc(nusize) ;
if (!destAddr)
hzexit(E_MEMORY, "Buffer of (%d) bytes", nusize) ;
destCtl = _strXlate(destAddr) ;
destCtl->_setSize(nusize) ;
memcpy(destCtl->_data(), thisCtl->_data() + wc, nusize) ;
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 ;
}