| Return Type | Function name | Arguments |
|---|---|---|
| hzString& | hzString::UrlEncode | (bool,) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::UrlEncode (bool bResv)
{
_hzfunc("hzString::UrlEncode") ;
_strItem* thisCtl ;
_strItem* destCtl ;
char* i ;
char* j ;
uint32_t nLen ;
uint32_t destAddr ;
char buf [4];
if (!m_addr)
return *this ;
thisCtl = (_strItem*) _strXlate(m_addr) ;
nLen = thisCtl->_getSize() ;
for (i = (char*) thisCtl->_data() ; *i ; i++)
{
if (*i == CHAR_PERCENT)
continue ;
if (IsUrlnorm(*i))
continue ;
if (IsUrlresv(*i))
{
if (bResv)
nLen += 2;
continue ;
}
nLen += 2;
}
if (nLen == thisCtl->_getSize())
return *this ;
destAddr = _strAlloc(nLen) ;
destCtl = (_strItem*) _strXlate(destAddr) ;
destCtl->_setSize(nLen) ;
destCtl->m_copy = 1;
j = (char*) destCtl->_data() ;
for (i = (char*) thisCtl->_data() ; *i ; i++)
{
if (*i == CHAR_PERCENT)
*j++ = *i ;
else if (IsUrlnorm(*i))
*j++ = *i ;
else if (IsUrlresv(*i) && !bResv)
*j++ = *i ;
else
{
*j++ = CHAR_PERCENT ;
sprintf(buf, "%02x", (uint32_t) *i) ;
*j++ = buf[0];
*j++ = buf[1];
}
}
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 ;
}