Purpose: Determine if a token could represent an entity of the form &#d..d; or &#xd..d; Note that because of the anticipated context in which the function will be used, the

Return TypeFunction nameArguments
boolIsEntity(uint32_t&,uint32_t&,const char*,)

Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp

Function Logic:

0:START 1:uVal nLen 2:unknown 3:Return false 4:unknown 5:Return false 6:tok 7:i 8:unknown 9:uVal nLen 10:Return true 11:unknown 12:uVal nLen 13:Return true 14:unknown 15:uVal nLen 16:Return true 17:unknown 18:uVal nLen 19:Return true 20:unknown 21:Return false 22:unknown 23:unknown 24:v 25:unknown 26:* 27:v 28:unknown 29:v * v 30:unknown 31:v * v 32:unknown 33:v * v 34:unknown 35:uVal c nLen 36:Return true 37:Return false

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 &#xd..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 ;
}