Text substitution Replace within this string, all instances of strA with strB. This string is unchanged if strA does not exist within it.
| Return Type | Function name | Arguments |
|---|---|---|
| hzString& | hzString::Replace | (const char*,const char*,) |
Declared in file: hzString.h
Defined in file : hzString.cpp
Function Logic:
Function body:
hzString& hzString::Replace (const char* strA)const char* strB,
{
// Text substitution
//
// Replace within this string, all instances of strA with strB. This string is unchanged if strA does not exist within it.
//
// Arguments: 1) strA Patern to be substituted out
// 2) strB Patern to be used instead
//
// Returns: Reference to this string in all cases
_hzfunc("hzString::Replace") ;
hzChain Z ; // Working chain buffer
_strItem* thisCtl ; // This string's control area
const char* i ; // Pointer into string data
uint32_t nLen ; // Lenth of supplied strings
bool bFound = false ; // Indicates string to be replace is found
if (!strA)
return *this ;
if (!m_addr)
return *this ;
thisCtl = _strXlate(m_addr) ;
nLen = strlen(strA) ;
i = (char*) thisCtl->_data() ;
if (strstr(i, strA))
{
for (; *i ;)
{
if (*i == strA[0])
{
if (!memcmp(i, strA, nLen))
{
bFound = true ;
if (strB && strB[0])
Z << strB ;
i += nLen ;
continue ;
}
}
Z.AddByte(*i) ;
i++ ;
}
}
if (bFound)
{ Clear() ; operator=(Z) ; }
return *this ;
}