Assumes the supplied character string pointer is the start of a hexadecimal number and reads the value. If there are 8 chars that match [0-9] or [a-f] or [A-F], true is returned and arg1 (int32_t&) is set to the hex value.
| Return Type | Function name | Arguments |
|---|---|---|
| bool | ReadHex | (int32_t&,const char*,) |
Declared and defined in file: hzTextproc.cpp
Function Logic:
Function body:
bool ReadHex (int32_t& nVal)const char* s,
{
// Category: Text Processing
//
// Assumes the supplied character string pointer is the start of a hexadecimal number and reads the value. If there are 8 chars that match
// [0-9] or [a-f] or [A-F], true is returned and arg1 (int32_t&) is set to the hex value.
//
// Arguments: 1) nVal The int32_t reference to be populated
// 2) s The char string assumed to be at the start of a hex number
//
// Returns: True If the supplied cstr amounted to a hex value
// False Otherwise
_hzfunc("ReadHex") ;
char* i = (char*) s ; // Need this because tolower violates const
int32_t v = 0; // Value being read
int32_t n = 0; // Number of chars processed
nVal = 0;
if (!i || !i[0])
return false ;
for (; *i && n < 8; i++, n++)
{
if (chartype[*i] & CTYPE_DIGIT)
{
v *= 16;
v += (*i - CHAR_0) ;
continue ;
}
*i = tolower(*i) ;
if (*i < ''a''||*i > ''f'')
return false ;
v *= 16;
v += 10;
v += (*i - ''a'');
}
nVal = v ;
return true ;
}