' DIGITAL%(2.0)  Check Char String for Digital Value   04/28/1997-03/27/2002
' --------------------------------------------------------------------------
' Copyright (C) 1997-2002 by Vladimir Veytsel                  www.davar.net

' Type ---------------------------------------------------------------------

'    Function (predicate)

' Description --------------------------------------------------------------

'    DIGITAL% function is a predicate that returns digital characteristic
'    of the specified string of possibly delimited digits.

' Declaration --------------------------------------------------------------

'    DECLARE FUNCTION DIGITAL%(Strng$,Delim$)

' Parameters ---------------------------------------------------------------

'    Strng$  - Character string to be checked for digital value
'    Delim$  - Legal delimiters within digital string
'              First character of the delimiter parameter may specify the
'              type of the digital test to be performed, in which case it
'              is considered to be a test type indicator (not a delimiter).
'              "D" or "d"  - Check for Decimal digits ("0123456789")
'              "O" or "o"  - Check for Octal   digits ("01234567")
'              "H" or "h"  - Check for Hex     digits ("0123456789AaBbCcDdEeFf")
'              "R" or "r"  - Check for Roman   digits ("IiVvXx")
'              If the first character of the delimiter parameter is none
'              of the above test type characters, it is considered to be
'              a delimiter and test is performed for Decimal digits.

' Value --------------------------------------------------------------------

'    If specified string is either EMPTY or entirely DIGITAL
'       (with the exception of specified legal delimiters),
'       then -1 (true)  is returned to the point of function invocation,
'       else  0 (false) is returned to the point of function invocation.

' Notes --------------------------------------------------------------------

'  - EMPTY string is considered to be DIGITAL in order to treat uniformly
'    the default parameters.

'    Roman digital test is formal - it checks that string consists only
'    of "IiVvXx" characters plus whatever specified legitimate delimiters.
'    Consistency of Roman numbers is NOT checked,
'    E.g.:  Strings like "IIV" or "XIIII" are considered Roman-digital,
'           thought they are clearly not Roman-numeric.

' Examples -----------------------------------------------------------------

'    DIGITAL%(""          ,"D"  )=-1
'    DIGITAL%(""          ,".:/")=-1
'    DIGITAL%("0123456789","d"  )=-1
'    DIGITAL%("0123456789",".:/")=-1
'    DIGITAL%("0.2.4.6.8" ,""   )= 0
'    DIGITAL%("0.2.4.6.8" ,"."  )=-1
'    DIGITAL%("0.2:4/6.8" ,""   )= 0
'    DIGITAL%("0.2:4/6.8" ,".:/")=-1
'    DIGITAL%("23456789"  ,"O"  )= 0
'    DIGITAL%("01234567"  ,"o"  )=-1
'    DIGITAL%("AbCdEfGh"  ,"H"  )= 0
'    DIGITAL%("89AbCdEf"  ,"h"  )=-1
'    DIGITAL%("IVX"       ,""   )= 0
'    DIGITAL%("IVX"       ,"R"  )=-1
'    DIGITAL%("I V X"     ,"R"  )= 0
'    DIGITAL%("i v x"     ,"r " )=-1
'    DIGITAL%("iivxiiii"  ,"r"  )=-1
'    DIGITAL%(" IVX-12 "  ,"R- ")= 0

' Start Function -----------------------------------------------------------

     FUNCTION DIGITAL%(Strng$,Delim$) PUBLIC

' Form and Return Function Value to the Point of Invocation ----------------

     SELECT CASE (UCASE$(LEFT$(Delim$,1)))
            CASE ("D")
                 DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"0123456789")=0)
            CASE ("O")
                 DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"01234567")=0)
            CASE ("H")
                 DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"0123456789AaBbCcDdEeFf")=0)
            CASE ("R")
                 DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"IiVvXx")=0)
            CASE ELSE
                 DIGITAL%=(VERIFY(Strng$,Delim$+"0123456789")=0)
     END SELECT

' Finish Function ----------------------------------------------------------

     END FUNCTION
