Locate country by country code

Return TypeFunction nameArguments
uint32_tGetCountryByCode(const char*,)

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

Function Logic:

0:START 1:unknown 2:Return 0 3:unknown 4:Return 0 5:unknown 6:Return 0 7:unknown 8:Return 0 9:unknown 10:Return 0 11:unknown 12:Return 0 13:unknown 14:Return 0 15:nPos bFound 16:unknown 17:unknown 18:unknown 19:nPos 20:s_CC_buffer 21:i 22:unknown 23:- 24:res 25:i[0] 26:res 27:items 28:unknown 29:unknown 30:nPos 31:unknown 32:unknown 33:nPos 34:bFound 35:Return bFound?nPos:0

Function body:

uint32_t GetCountryByCode (const char* ccode)
{
   //  Category: Internet
   //  
   //  Locate country by country code
   //  
   //  Argument: ccode Two letter country code
   //  
   //  Returns: Number being RID of country or 0 if not found.
   _hzfunc(__func__) ;
   const char* i ;         //  In-table country code
   uint32_t    nDiv ;      //  Binary chop divider
   uint32_t    nPos ;      //  Starting position
   int32_t     res ;       //  Comparison result
   bool        bFound ;    //  Position if redult
   //  Ensure country code shared memory is in place
   if (!s_CC_buffer)
       return 0;
   //  Ensure country code is two upper case letters
   if (!ccode)     return 0;
   if (!ccode[0])  return 0;
   if (ccode[2])   return 0;
   if (ccode[0]< ''A''||ccode[0]> ''Z'')return0;
   if (ccode[1]< ''A''||ccode[1]> ''Z'')return0;
   //  Perform binary chop
   if (!s_CC_start)
       return 0;
   nPos = s_CC_start ;
   bFound = false ;
   for (nDiv = s_CC_div ;; nDiv /= 2)
   {
       if (nPos > s_CC_max)
       {
           if (!nDiv)
               break ;
           nPos -= nDiv ;
           continue ;
       }
       //  Compare
       i = s_CC_buffer + s_CC_offsets[nPos] ;
       if (i[0]> ccode[0])
           res = -1;
       else if (i[0]< ccode[0])
           res = 1;
       else
           res = i[1]> ccode[1]? -1: i[1]< ccode[1]? 1: 0;
       //  Chop
       if (res > 0)
       {
           if (!nDiv)
               break ;
           nPos += nDiv ;
           continue ;
       }
       if (res < 0)
       {
           if (!nDiv)
               break ;
           nPos -= nDiv ;
           continue ;
       }
       bFound = true ;
       break ;
   }
   return bFound ? nPos : 0;
}