@@ -52,6 +52,7 @@ subroutine collect_ascii(testsuite)
5252 new_unittest(" to_lower_long" , test_to_lower_long), &
5353 new_unittest(" to_upper_short" , test_to_upper_short), &
5454 new_unittest(" to_upper_long" , test_to_upper_long), &
55+ new_unittest(" ascii_table" , test_ascii_table), &
5556 new_unittest(" to_upper_string" , test_to_upper_string), &
5657 new_unittest(" to_lower_string" , test_to_lower_string), &
5758 new_unittest(" to_title_string" , test_to_title_string), &
@@ -725,52 +726,27 @@ subroutine test_to_upper_long(error)
725726 ! This test reproduces the true/false table found at
726727 ! https://en.cppreference.com/w/cpp/string/byte
727728 !
728- subroutine test_ascii_table
729+ subroutine ascii_table (table )
730+ logical , intent (out ) :: table(15 ,12 )
729731 integer :: i, j
730- logical :: table(15 ,12 )
731- 732- abstract interface
733- pure logical function validation_func_interface(c)
734- character (len= 1 ), intent (in ) :: c
735- end function
736- end interface
737- 738- type :: proc_pointer_array
739- procedure (validation_func_interface), pointer , nopass :: pcf
740- end type proc_pointer_array
741- 742- type (proc_pointer_array) :: pcfs(12 )
743- 744- pcfs(1 )% pcf = > is_control
745- pcfs(2 )% pcf = > is_printable
746- pcfs(3 )% pcf = > is_white
747- pcfs(4 )% pcf = > is_blank
748- pcfs(5 )% pcf = > is_graphical
749- pcfs(6 )% pcf = > is_punctuation
750- pcfs(7 )% pcf = > is_alphanum
751- pcfs(8 )% pcf = > is_alpha
752- pcfs(9 )% pcf = > is_upper
753- pcfs(10 )% pcf = > is_lower
754- pcfs(11 )% pcf = > is_digit
755- pcfs(12 )% pcf = > is_hex_digit
756732
757733 ! loop through functions
758734 do i = 1 , 12
759- table(1 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 0 ,8 )])! control codes
760- table(2 ,i) = pcfs(i) % pcf( achar ( 9 )) ! tab
761- table(3 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 10 ,13 )])! whitespaces
762- table(4 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 14 ,31 )])! control codes
763- table(5 ,i) = pcfs(i) % pcf( achar ( 32 )) ! space
764- table(6 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 33 ,47 )])! !"#$%&'()*+,-./
765- table(7 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 48 ,57 )])! 0123456789
766- table(8 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 58 ,64 )])! :;<=>?@
767- table(9 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 65 ,70 )])! ABCDEF
768- table(10 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 71 ,90 )])! GHIJKLMNOPQRSTUVWXYZ
769- table(11 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 91 ,96 )])! [\]^_`
770- table(12 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 97 ,102 )])! abcdef
771- table(13 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 103 ,122 )])! ghijklmnopqrstuvwxyz
772- table(14 ,i) = all ([(pcfs(i) % pcf( achar (j)), j= 123 ,126 )])! {|}~
773- table(15 ,i) = pcfs(i) % pcf( achar ( 127 )) ! backspace character
735+ table(1 ,i) = all ([(validate(j,i), j= 0 ,8 )])
736+ table(2 ,i) = validate( 9 ,i)
737+ table(3 ,i) = all ([(validate(j,i), j= 10 ,13 )])
738+ table(4 ,i) = all ([(validate(j,i), j= 14 ,31 )])
739+ table(5 ,i) = validate( 32 ,i)
740+ table(6 ,i) = all ([(validate(j,i), j= 33 ,47 )])
741+ table(7 ,i) = all ([(validate(j,i), j= 48 ,57 )])
742+ table(8 ,i) = all ([(validate(j,i), j= 58 ,64 )])
743+ table(9 ,i) = all ([(validate(j,i), j= 65 ,70 )])
744+ table(10 ,i) = all ([(validate(j,i), j= 71 ,90 )])
745+ table(11 ,i) = all ([(validate(j,i), j= 91 ,96 )])
746+ table(12 ,i) = all ([(validate(j,i), j= 97 ,102 )])
747+ table(13 ,i) = all ([(validate(j,i), j= 103 ,122 )])
748+ table(14 ,i) = all ([(validate(j,i), j= 123 ,126 )])
749+ table(15 ,i) = validate( 127 ,i)
774750 end do
775751
776752 ! output table for verification
@@ -779,6 +755,59 @@ pure logical function validation_func_interface(c)
779755 write (* ,' (I3,2X,12(L4),2X,I3)' ) j, (table(j,i),i= 1 ,12 ), count (table(j,:))
780756 end do
781757 write (* ,' (5X,12(I4))' ) (count (table(:,i)),i= 1 ,12 )
758+ 759+ contains
760+ 761+ elemental logical function validate(ascii_code, func)
762+ integer , intent (in ) :: ascii_code, func
763+ character (len= 1 ) :: c
764+ 765+ c = achar (ascii_code)
766+ 767+ select case (func)
768+ case (1 ); validate = is_control(c)
769+ case (2 ); validate = is_printable(c)
770+ case (3 ); validate = is_white(c)
771+ case (4 ); validate = is_blank(c)
772+ case (5 ); validate = is_graphical(c)
773+ case (6 ); validate = is_punctuation(c)
774+ case (7 ); validate = is_alphanum(c)
775+ case (8 ); validate = is_alpha(c)
776+ case (9 ); validate = is_upper(c)
777+ case (10 ); validate = is_lower(c)
778+ case (11 ); validate = is_digit(c)
779+ case (12 ); validate = is_hex_digit(c)
780+ case default ; validate = .false.
781+ end select
782+ end function validate
783+ 784+ end subroutine ascii_table
785+ 786+ subroutine test_ascii_table (error )
787+ type (error_type), allocatable , intent (out ) :: error
788+ logical :: arr(15 , 12 )
789+ logical , parameter :: ascii_class_table(15 ,12 ) = transpose (reshape ([ &
790+ ! iscntrl isprint isspace isblank isgraph ispunct isalnum isalpha isupper islower isdigit isxdigit
791+ .true. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 0–8
792+ .true. , .false. , .true. , .true. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 9
793+ .true. , .false. , .true. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 10–13
794+ .true. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 14–31
795+ .false. , .true. , .true. , .true. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 32 (space)
796+ .false. , .true. , .false. , .false. , .true. , .true. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 33–47
797+ .false. , .true. , .false. , .false. , .true. , .false. , .true. , .false. , .false. , .false. , .true. , .true. , & ! 48–57
798+ .false. , .true. , .false. , .false. , .true. , .true. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 58–64
799+ .false. , .true. , .false. , .false. , .true. , .false. , .true. , .true. , .true. , .false. , .false. , .true. , & ! 65–70
800+ .false. , .true. , .false. , .false. , .true. , .false. , .true. , .true. , .true. , .false. , .false. , .false. , & ! 71–90
801+ .false. , .true. , .false. , .false. , .true. , .true. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 91–96
802+ .false. , .true. , .false. , .false. , .true. , .false. , .true. , .true. , .false. , .true. , .false. , .true. , & ! 97–102
803+ .false. , .true. , .false. , .false. , .true. , .false. , .true. , .true. , .false. , .true. , .false. , .false. , & ! 103–122
804+ .false. , .true. , .false. , .false. , .true. , .true. , .false. , .false. , .false. , .false. , .false. , .false. , & ! 123–126
805+ .true. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. , .false. & ! 127
806+ ], shape= [12 ,15 ]))
807+ 808+ call ascii_table(arr)
809+ call check(error, all (arr .eqv. ascii_class_table), " ascii table was not accurately generated" )
810+ 782811 end subroutine test_ascii_table
783812
784813 subroutine test_to_lower_string (error )
0 commit comments