Tests if a supplied string (or text at a hzChain iterator) is of the form of an email address. To qualify, there must be a single occurence of '@' both preceeded and followed by strings of non-zero length whose characters are members of a set of permitted characters (see below). There also must be at least one period in the string following the @. Additionally the length of the whole must not exceed 255. The first instance of a whitespace character (<= space) terminates the test. If the string up to but not including the whitespace character or null terminator, then the test is passed, otherwise it fails. Permitted chars on the LHS of the '@' are: [a-z], [A-Z], [0-9], [!, #, $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, }, ~] and the period (.) if it is not the last character in the string. Permitted chars on the LHS of the '@' are: [a-z], [A-Z], [0-9] and the period (.) or minus sign (-) if they are not the last character in the string.

Return TypeFunction nameArguments
boolIsEmaddr(const char*,)

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

Function Logic:

0:START 1:unknown 2:Return false 3:unknown 4:unknown 5:unknown 6:items 7:unknown 8:Return false 9:unknown 10:Return false 11:unknown 12:unknown 13:Return false 14:unknown 15:bPeriod 16:unknown 17:items 18:unknown 19:Return false 20:unknown 21:Return true 22:Return false

Function body:

bool IsEmaddr (const char* cpStr)
{
   //  Category: Text Processing
   //  
   //  Tests if a supplied string (or text at a hzChain iterator) is of the form of an email address. To qualify, there must be a single occurence
   //  of '@' both preceeded and followed by strings of non-zero length whose characters are members of a set of permitted characters (see below).
   //  There also must be at least one period in the string following the @. Additionally the length of the whole must not exceed 255.
   //  
   //  The first instance of a whitespace character (<= space) terminates the test. If the string up to but not including the whitespace character
   //  or null terminator, then the test is passed, otherwise it fails.
   //  
   //  Permitted chars on the LHS of the '@' are: [a-z], [A-Z], [0-9], [!, #, $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, }, ~] and the period (.)
   //  if it is not the last character in the string.
   //  
   //  Permitted chars on the LHS of the '@' are: [a-z], [A-Z], [0-9] and the period (.) or minus sign (-) if they are not the last character in the
   //  string.
   //  
   //  Arguments: 1) cpStr The char pointer to be tested
   //  
   //  Returns: True If the supplied cstr sets the email address
   //     False Otherwise
   _hzfunc("IsEmaddr") ;
   const char* i ;                 //  Source string iterator
   uint32_t    nLhs = 0;           //  Count to the left of the @
   uint32_t    nRhs = 0;           //  Count to the right of the @
   bool        bPeriod = false ;   //  Confirmed period
   if (!cpStr || !cpStr[0])
       return false ;
   //  Count chars upto the @
   for (i = cpStr ; *i > CHAR_SPACE ; i++)
   {
       if (*i == CHAR_AT)
           break ;
       if ((*i >&eq; ''a''&&*i <&eq; ''z'')||(*i >&eq; ''A''&&*i <&eq; ''Z'')||(*i >&eq; ''0''&&*i <&eq; ''9'')
           || *i==''!''||*i==''#''||*i==''$''||*i==''%''||*i==''&''||*i=='''''|| *i==''*''||*i==''+''||*i==''-''
           || *i==''/''||*i==''=''||*i==''?''||*i==''^''||*i==''_''||*i==''`''||*i==''{''||*i==''|''||*i==''}''||*i==''~''
           || (*i==''.''&&i[1]> '' ''&&i[1]!= ''@''&&nLhs))
       {
           nLhs++ ;
           if (nLhs > 63)
               return false ;
           continue ;
       }
       break ;
   }
   if (*i != CHAR_AT || !nLhs)
       return false ;
   //  Count chars beyond @
   for (i++ ; *i > CHAR_SPACE ; i++)
   {
       if (*i == CHAR_AT)
           return false ;
       if (*i == CHAR_PERIOD && i[1]&& i[1]!= CHAR_PERIOD)
           { bPeriod = true ; continue ; }
       if ((*i >&eq; ''a''&&*i <&eq; ''z'')||(*i >&eq; ''A''&&*i <&eq; ''Z'')||(*i >&eq; ''0''&&*i <&eq; ''9'')
           || (*i==''-''&&i[1]> '' ''&&nRhs)
           || (*i==''.''&&i[1]> '' ''&&nRhs))
       {
           nRhs++ ;
           if (nRhs > 192)
               return false ;
           continue ;
       }
       break ;
   }
   if (bPeriod && nLhs && nRhs > 2)
       return true ;
   return false ;
}