Effect a grep on the supplied exp to the input chain. Place all matching lines in the output chain
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | Grep | (hzChain&,hzChain&,const char*,) |
Declared in file: hzTextproc.h
Defined in file : hzRegex.cpp
Function Logic:
Function body:
hzEcode Grep (hzChain& Zo)hzChain& Zi, const char* exp,
{
// Category: Regular Expression
//
// Effect a grep on the supplied exp to the input chain. Place all matching lines in the output chain
//
// Arguments: 1) Zo The output chain being a list of matching lines
// 2) Zi The input chain
// 3) exp The test expression
//
// Returns: E_ARGUMENT If no search expression is supplied
// E_OK In all other circumstances
_hzfunc(__func__) ;
hzChain::Iter zi ; // For iteration of the input
hzChain L ; // For isolating a line. This is then tested for the expression. If it passes, it is added as is to the output.
hzString S ; // Temp string
Zo.Clear() ;
if (!Zi.Size())
return E_OK ;
if (!exp || !exp[0])
return E_ARGUMENT ;
for (zi = Zi ; !zi.eof() ; zi++)
{
if (*zi != CHAR_NL)
{ L.AddByte(*zi) ; continue ; }
// Now have a line in L
S = L ;
L.Clear() ;
if (!FormCheckCstr(*S, exp))
continue ;
// Line has passed so add
Zo << S ;
Zo.AddByte(CHAR_NL) ;
L.Clear() ;
}
return E_OK ;
}