Convert string to all lower case. As this function can alter string content, it follows the protocol described in chapter 3.1 "Smart Pointers" in the HadronZoo Library manual. Arguments: None
| Return Type | Function name | Arguments |
|---|---|---|
| hzString& | hzString::ToLower | (void) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::ToLower (void)
{
// Convert string to all lower case.
//
// As this function can alter string content, it follows the protocol described in chapter 3.1 "Smart Pointers" in the HadronZoo Library manual.
//
// Arguments: None
// Returns: Reference to this string instance
_hzfunc("hzString::ToLower") ;
_strItem* thisCtl ; // This string's control area
_strItem* destCtl ; // New internal structure if required
char* i ; // Iterator
char* j ; // Iterator
uint32_t count ; // Char counter
uint32_t destAddr ; // New string address if required
bool bChange ; // Flag to indicate if operation chages content
// If NULL return
if (!m_addr)
return *this ;
thisCtl = _strXlate(m_addr) ;
// Is change needed?
bChange = false ;
for (i = (char*) thisCtl->_data(), count = thisCtl->_getSize() ; count ; count--, i++)
{
if (*i >&eq; ''A''&&*i <&eq; ''Z'')
{ bChange = true ; break ; }
}
if (!bChange)
return *this ;
// Allocate new space
count = thisCtl->_getSize() ;
destAddr = _strAlloc(count) ;
destCtl = _strXlate(destAddr) ;
destCtl->_setSize(count) ;
destCtl->m_copy = 1;
i = (char*) thisCtl->_data() ;
j = (char*) destCtl->_data() ;
// The new string space is populated
for (; count ; count--)
*j++ = tolower(*i++) ;
// Tidy up
if (thisCtl->m_copy && thisCtl->m_copy < 50)
{
if (__sync_add_and_fetch(&(thisCtl->m_copy), -1)== 0)
_strFree(m_addr, thisCtl->_getSize()) ;
}
m_addr = destAddr ;
return *this ;
}