Purpose: Determine if a token could represent an entity of the form &#d..d; or 
..d; Note that because of the anticipated context in which the function will be used, the
| Return Type | Function name | Arguments |
|---|---|---|
| bool | IsEntity | (uint32_t&,uint32_t&,const char*,) |
Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp
Function Logic:
Function body:
bool IsEntity (uint32_t& uVal)uint32_t& nLen, const char* tok,
{
// Category: Text Processing
//
// Purpose: Determine if a token could represent an entity of the form &#d..d; or 
..d;
// Note that because of the anticipated context in which the function will be used,
// the
//
// Arguments: 1) uVal A refernece to the result (int32_t)
// 2) nLen The length of the token if confirmed as an entity.
// 3) tok The token (const char*)
//
// Returns: True If token could be a valid large integer
// False If string of zero length or contains non numeric chars
uint32_t v = 0; // Value
int32_t c = 0; // Iterator
const char* i ; // Pointer into token
uVal = 0;
nLen = 0;
// First char must be an ampersand
if (!tok) return false ;
if (tok[0]!= ''&'') return false ;
// Second char could be start of a non-numeric entity
i = tok + 1;
if (*i == ''a''&&memcmp(i, "amp;", 4)== 0) { uVal = 38;nLen = 5; return true ; }
if (*i == ''g''&&memcmp(i, "gt;", 3)== 0) { uVal = 62;nLen = 4; return true ; }
if (*i == ''l''&&memcmp(i, "lt;", 3)== 0) { uVal = 60;nLen = 4; return true ; }
if (*i == ''n''&&memcmp(i, "nbsp;", 5)== 0) { uVal = 32;nLen = 6; return true ; }
// Now we only consider numeric entities and for these the second char must be a hash
if (tok[1]!= ''#'') return false ;
if (tok[2]== ''x'')
{
// Suspect a hexadecimal entity
for (c = 3,i = tok + c ; IsHex(*i) ; c++, i++)
{
v *= 16;
if (*i >&eq; ''0''&&*i <&eq; ''9''){v += (*i - ''0'');continue ; }
if (*i >&eq; ''A''&&*i <&eq; ''F''){v += 10;v += (*i - ''A'');continue ; }
if (*i >&eq; ''a''&&*i <&eq; ''f''){v += 10;v += (*i - ''a'');continue ; }
break ;
}
}
else
{
// Suspect a decimal entity
for (c = 2,i = tok + c ; IsDigit(*i) ; c++, i++)
{
v *= 10;
v += (*i - ''0'');
}
}
if (*i == '';'')
{
// Entity confirmed
uVal = v ;
nLen = c + 1;
return true ;
}
return false ;
}