Performs URL-Decoding on the current string content. If the current string does not contain URL-encoded sequences, the string will be unchanged. Arguments: None
| Return Type | Function name | Arguments |
|---|---|---|
| hzString& | hzString::UrlDecode | (void) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::UrlDecode (void)
{
// Performs URL-Decoding on the current string content. If the current string does not contain URL-encoded sequences, the string will be unchanged.
//
// Arguments: None
// Returns: Reference to this string instance
_hzfunc("hzString::UrlDecode") ;
_strItem* thisCtl ; // This string's control area
_strItem* destCtl ; // New string's control area
char* i ; // Pointer into old string data
char* j ; // Pointer into new string data
uint32_t destAddr ; // New string space address
uint32_t newLen = 0; // Length of new string
uint32_t val ; // Hex value
// If NULL return
if (!m_addr)
return *this ;
thisCtl = _strXlate(m_addr) ;
// Is change needed? Not unless there are incidences of a percent followed by two hex chars
for (i = thisCtl->_data() ; *i ; i++)
{
if (*i == CHAR_PERCENT && IsHex(i[1])&& IsHex(i[2]))
i += 2;
newLen++ ;
}
if (newLen == thisCtl->_getSize())
return *this ;
// Allocate new space
destAddr = _strAlloc(newLen) ;
destCtl = _strXlate(destAddr) ;
destCtl->_setSize(newLen) ;
destCtl->m_copy = 1;
// Create new string
for (j = destCtl->_data(), i = thisCtl->_data() ; *i ; i++)
{
if (*i == CHAR_PERCENT)
{
if (IsHex(i[1])&& IsHex(i[2]))
{
i++ ;
val = (*i >&eq;''0''&&*i <&eq;''9''?*i-''0'':*i >&eq; ''A''&&*i<&eq; ''F''?*i+10-''A'':*i>&eq;''a''&&*i<&eq;''f''?*i+10-''a'':0);
val *= 16;
i++ ;
val += (*i >&eq;''0''&&*i <&eq;''9''?*i-''0'':*i >&eq; ''A''&&*i<&eq; ''F''?*i+10-''A'':*i>&eq;''a''&&*i<&eq;''f''?*i+10-''a'':0);
*j++ = (char) val ;
continue ;
}
}
*j++ = *i ;
}
// 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 ;
}