Convert string to all upper 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::ToUpper | (void) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::ToUpper (void)
{
// Convert string to all upper 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::ToUpper") ;
_strItem* thisCtl ; // This string's control area
_strItem* destCtl ; // New internal structure if required
char* i ; // Iterator
char* j ; // Iterator
uint32_t nLen ; // Length
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(), nLen = thisCtl->_getSize() ; nLen ; i++, nLen--)
{
if (*i >&eq; ''a''&&*i <&eq; ''z'')
{ bChange = true ; break ; }
}
if (!bChange)
return *this ;
// Allocate new space
nLen = thisCtl->_getSize() ;
destAddr = _strAlloc(nLen) ;
destCtl = _strXlate(destAddr) ;
destCtl->_setSize(nLen) ;
destCtl->m_copy = 1;
i = (char*) thisCtl->_data() ;
j = (char*) destCtl->_data() ;
for (; nLen ; nLen--)
*j++ = toupper(*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 ;
}