valid_json_hex Function

private purefunction valid_json_hex(str) result(valid)

Arguments

Type IntentOptional AttributesName
character(kind=CK,len=*), intent(in) :: str

the string to check.

Return Value logical(kind=LK)

is str a value 4-digit hex string

Description

Returns true if the string is a valid 4-digit hex string.

Examples

    valid_json_hex('0000')  !returns true
    valid_json_hex('ABC4')  !returns true
    valid_json_hex('AB')    !returns false (< 4 characters)
    valid_json_hex('WXYZ')  !returns false (invalid characters)

Called By

proc~~valid_json_hex~~CalledByGraph proc~valid_json_hex valid_json_hex proc~parse_string parse_string proc~parse_string->proc~valid_json_hex proc~parse_value parse_value proc~parse_value->proc~parse_string proc~parse_object parse_object proc~parse_value->proc~parse_object proc~parse_array parse_array proc~parse_value->proc~parse_array proc~parse_object->proc~parse_string proc~parse_object->proc~parse_value proc~parse_object->proc~parse_object proc~json_parse_string json_parse_string proc~json_parse_string->proc~parse_value proc~json_parse_file json_parse_file proc~json_parse_file->proc~parse_value proc~parse_array->proc~parse_value proc~wrap_json_parse_string wrap_json_parse_string proc~wrap_json_parse_string->proc~json_parse_string interface~json_parse json_parse interface~json_parse->proc~json_parse_string interface~json_parse->proc~json_parse_file proc~test_14 test_14 proc~test_14->interface~json_parse proc~test_8 test_8 proc~test_8->interface~json_parse proc~json_file_load json_file_load proc~json_file_load->interface~json_parse proc~json_file_load_from_string json_file_load_from_string proc~json_file_load_from_string->interface~json_parse program~jf_test_14 jf_test_14 program~jf_test_14->proc~test_14 program~jf_test_8 jf_test_8 program~jf_test_8->proc~test_8 proc~wrap_json_file_load_from_string wrap_json_file_load_from_string proc~wrap_json_file_load_from_string->proc~json_file_load_from_string
Help

Variables

TypeVisibility AttributesNameInitial
integer(kind=IK), public :: n
integer(kind=IK), public :: i
character(kind=CK,len=1), public, parameter, dimension(22):: valid_chars =[(achar(i), i=48, 57), (achar(i), i=65, 70), (achar(i), i=97, 102)]

Source Code

    pure function valid_json_hex(str) result(valid)

    implicit none

    logical(LK)                         :: valid  !! is str a value 4-digit hex string
    character(kind=CK,len=*),intent(in) :: str    !! the string to check.

    integer(IK) :: n,i

    !an array of the valid hex characters:
    character(kind=CK,len=1),dimension(22),parameter :: valid_chars = &
        [ (achar(i),i=48,57), & ! decimal digits
          (achar(i),i=65,70), & ! capital A-F
          (achar(i),i=97,102) ] ! lowercase a-f

    !initialize
    valid = .false.

    !check all the characters in the string:
    n = len(str)
    if (n==4) then
        do i=1,n
            if (.not. any(str(i:i)==valid_chars)) return
        end do
        valid = .true.    !all are in the set, so it is OK
    end if

    end function valid_json_hex