Determine if the supplied chain iterator is at the start of a numeric entity of the form &#x[hex number]; or &#[dec number]; Note: This function always leaves the supplied iterator unchanged in accordance with the HadronZoo text-processing rules.
| Return Type | Function name | Arguments |
|---|---|---|
| bool | AtEntity | (uint32_t&,uint32_t&,hzChain::Iter&,) |
Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp
Function Logic:
Function body:
bool AtEntity (uint32_t& uVal)uint32_t& entLen, hzChain::Iter& zi,
{
// Category: Text Processing
//
// Determine if the supplied chain iterator is at the start of a numeric entity of the form &#x[hex number]; or &#[dec number];
//
// Arguments: 1) uVal The value of the entity.
// 2) entLen The length of the entity
// 3) zi The chain iterator.
//
// Returns: True If the chain iterator is at the start of a valid entity
// False Otherwise
//
// Note: This function always leaves the supplied iterator unchanged in accordance with the HadronZoo text-processing rules.
_hzfunc(__func__) ;
chIter xi ; // Input chain iterator
uint32_t nLen ; // Length of entity
uVal = entLen = 0;
nLen = 0;
// First char must be an ampersand
xi = zi ;
if (*xi != CHAR_AMPSAND)
return false ;
// Second char could be start of a non-numeric entity
xi++ ;
if (*xi == ''a''&&xi == "amp;") { uVal = 38;return 5; }
if (*xi == ''g''&&xi == "gt;") { uVal = 62;return 4; }
if (*xi == ''l''&&xi == "lt;") { uVal = 60;return 4; }
if (*xi == ''n''&&xi == "nbsp;") { uVal = 32;return 6; }
// Now we only consider numeric entities and for these the second char must be a hash
if (*xi != CHAR_HASH)
return false ;
xi++ ;
if (*xi == ''x'')
{
// Examining a suspected hex entity
nLen = 4;
for (xi++ ; !xi.eof() && IsHex(*xi) ; nLen++, xi++)
{
uVal *= 16;
if (*xi >&eq; ''0''&&*xi <&eq; ''9''){uVal += (*xi - ''0'');continue ; }
if (*xi >&eq; ''A''&&*xi <&eq; ''F''){uVal += 10;uVal += (*xi - ''A'');continue ; }
if (*xi >&eq; ''a''&&*xi <&eq; ''f''){uVal += 10;uVal += (*xi - ''a'');continue ; }
break ;
}
}
else
{
// Expecting a decimal entity
nLen = 3;
for (; !xi.eof() && IsDigit(*xi) ; nLen++, xi++)
{
uVal *= 10;
uVal += (*xi - ''0'');
}
}
if (*xi == '';'')
{
// Entity confirmed
entLen = nLen ;
return true ;
}
uVal = 0;
return false ;
}