Returns true if the string is a valid 4-digit hex string.
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)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK,len=*), | intent(in) | :: | str | the string to check. |
is str a value 4-digit hex string
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
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 !! length of `str`
integer(IK) :: i !! counter
!> 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