#ifndef GPIB_PARSER_VALIDATORS_NUMBERS_H
#define GPIB_PARSER_VALIDATORS_NUMBERS_H

#include <ctype.h> // isalpha, isdigit
#include "gpib_parser_casts.h"

#define IsDigit(ch)              MAKE_BOOL(isdigit(ch))
#define IsNUMBER(ch)             IsDigit(ch)
#define IsNumber(ch)             IsDigit(ch)


/* UNUSED
#define IsSIGN(character)        MAKE_BOOL((character)=='+' || (character)=='-')
#define IsEXPCHAR(character)     MAKE_BOOL(((character)&0xDF)=='E')
#define IsHEXOnly(character)     MAKE_BOOL(((character) & 0xDF)<='F' && ((character) & 0xDF)>='A')
#define IsHEXorDEC(character)    MAKE_BOOL(IsHEX(character) || IsDEC(character))
*/
//------------------------------------------------------------------------------
// IsExponentialChar:
// Check whether the character @ch is a valid charater for a exponential number format
static inline BOOL IsExponentialChar( const char ch )
{
   return MAKE_BOOL(
                    isdigit( ch )   // Allow a demical digit
                 ||   'E' == ch     // Allow a 'E' character
                 ||   'e' == ch     // Allow a 'e' character  
                 ||   '.' == ch     // Allow a dot character
                 ||   '+' == ch     // Allow a '+' sign
                 ||   '-' == ch     // Allow a '-' sign
                );
   
   /* #define IsEXP(character)         MAKE_BOOL(IsEXPCHAR(character) || IsFloatChar(character) || IsSIGN(character)) */
}
//------------------------------------------------------------------------------
// IsFloatChar:
// Check whether the character @ch is a valid charater for a float number
static inline BOOL IsFloatChar( const char ch )
{
   return MAKE_BOOL(
                    isdigit( ch )   // Allow a demical digit
                 ||   '.' == ch     // Allow a dot character
                 ||   '+' == ch     // Allow a '+' sign
                 ||   '-' == ch     // Allow a '-' sign
                );
   
   /* #define IsPOINT(character)       MAKE_BOOL((character)=='.') */
   /* #define IsFLOAT(character)       MAKE_BOOL(IsDEC(character) || IsPOINT(character)) */
}
//------------------------------------------------------------------------------
// IsBinaryChar:
// Check whether the character @ch is a valid charater for a binary number format
static inline BOOL IsBinaryChar( const char ch )
{
   return MAKE_BOOL(   '0' == ch     // Allow '0' character
                 || '1' == ch     // Allow '1' character
                );
   /* #define IsBIN(character)         MAKE_BOOL((character)<='1' && (character)>='0') */
}
//------------------------------------------------------------------------------
// IsOCT_Int32Overflow:
// This is a limited version of IsOctalChar() for the checking of overflowing the 32-bit interger
// This designed to check the most significant character of octal number for 32-bit integer overflowing.
// It is assumed to be applied to '37777777777' octal number.
static inline BOOL IsOCT_Int32Overflow( const char ch )
{
   return MAKE_BOOL( ( '0' <= ch ) && ( ch <= '3' ) );  // Allow characters '0'...'3'.
   
   /* #define IsOCTCorrect(character)  MAKE_BOOL((character)<='3' && (character)>='0') */
}
//------------------------------------------------------------------------------
// IsOctalChar:
// Check whether the character @ch is a valid charater for a octal number format
static inline BOOL IsOctalChar( char ch )
{
   return MAKE_BOOL( ( '0' <= ch ) && ( ch <= '7' ) );  // Allow characters '0', '1', ..., '7'.
   
   /* #define IsOCT(character)         MAKE_BOOL((character)<='7' && (character)>='0') */
}
//------------------------------------------------------------------------------
// IsHexademicalChar:
// Check whether the character @ch is a valid charater for a hexademical integer number
static inline BOOL IsHexademicalChar( char ch )
{
   ch = tolower( ch );       // Make the @ch to be a lower case
   
   // Note: tolower() for a demical characters ('0', '1', ... '9') is the same character
   
   return MAKE_BOOL(
                    isdigit( ch )   // Allow a demical digit
                 || ( ('a' <= ch) && (ch <= 'f') )
                );
   /* #define IsHEX(character)         MAKE_BOOL(IsHEXOnly(character) || IsNUMBER(character)) */
}
//------------------------------------------------------------------------------
// IsDemicalChar:
// Check whether the character @ch is a valid charater for a demical integer number
static inline BOOL IsDemicalChar( const char ch )
{
   return MAKE_BOOL(
                    isdigit( ch )   // Allow a demical digit
                 ||   '+' == ch     // Allow a '+' sign
                 ||   '-' == ch     // Allow a '-' sign
                );
   /* #define IsNUMBER(character)      MAKE_BOOL((character)<='9' && (character)>='0') */
   /* #define IsDEC(character)         MAKE_BOOL(IsNUMBER(character) || (character)=='+' || (character)=='-') */
}


#endif