search Program

program~~search~~UsesGraph program~search search iso_fortran_env iso_fortran_env iso_fortran_env->program~search module~penf_stringify~3 penf_stringify iso_fortran_env->module~penf_stringify~3 module~stringifor stringifor module~stringifor->program~search module~stringifor_string_t stringifor_string_t module~stringifor_string_t->module~stringifor module~penf~3 penf module~penf~3->module~stringifor module~penf~3->module~stringifor_string_t module~befor64 befor64 module~penf~3->module~befor64 module~befor64_pack_data_m~2 befor64_pack_data_m module~penf~3->module~befor64_pack_data_m~2 module~befor64->module~stringifor_string_t module~befor64_pack_data_m~2->module~befor64 module~penf_global_parameters_variables penf_global_parameters_variables module~penf_global_parameters_variables->module~penf~3 module~penf_b_size~4 penf_b_size module~penf_global_parameters_variables->module~penf_b_size~4 module~penf_global_parameters_variables->module~penf_stringify~3 module~penf_b_size~4->module~penf~3 module~penf_b_size~4->module~penf_stringify~3 module~penf_stringify~3->module~penf~3
Help


StringiFor search test.


Source Code


Variables

Type AttributesNameInitial
type(string) :: astring

A string.

type(string) :: anotherstring

Another string.

character(len=:), allocatable:: acharacter

A character.

integer :: istart

Start index of searched tag.

integer :: iend

End index of searched tag.

logical :: test_passed(5)

List of passed tests.


Source Code

program search
!-----------------------------------------------------------------------------------------------------------------------------------
!< StringiFor `search` test.
!-----------------------------------------------------------------------------------------------------------------------------------
use, intrinsic :: iso_fortran_env, only : stdout => output_unit
use stringifor, only : string
!-----------------------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------------------
implicit none
type(string)                  :: astring        !< A string.
type(string)                  :: anotherstring  !< Another string.
character(len=:), allocatable :: acharacter     !< A character.
integer                       :: istart         !< Start index of searched tag.
integer                       :: iend           !< End index of searched tag.
logical                       :: test_passed(5) !< List of passed tests.
!-----------------------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------------------
test_passed = .false.

astring = '<test> <first> hello </first> <first> not the first </first> </test>'
anotherstring = astring%search(tag_start='<first>', tag_end='</first>')
test_passed(1) = anotherstring//''=='<first> hello </first>'
write(stdout, "(A)") 'Original:  "'//astring//'"'
write(stdout, "(A,L1)") 'Search: "'//anotherstring//'", is correct? ', test_passed(1)

astring = '<test> <a> <a> <a> the nested a </a> </a> </a> </test>'
anotherstring = astring%search(tag_start='<a>', tag_end='</a>')
test_passed(2) = anotherstring//''=='<a> <a> <a> the nested a </a> </a> </a>'
write(stdout, "(A)") new_line('a')//'Original:  "'//astring//'"'
write(stdout, "(A,L1)") 'Search: "'//anotherstring//'", is correct? ', test_passed(2)

call astring%free
anotherstring = '<test> <a> <a> <a> the nested a </a> </a> </a> </test>'
astring = astring%search(in_string=anotherstring, tag_start='<a>', tag_end='</a>')
test_passed(3) = astring//''=='<a> <a> <a> the nested a </a> </a> </a>'
write(stdout, "(A)") new_line('a')//'Original:  "'//anotherstring//'"'
write(stdout, "(A,L1)") 'Search: "'//astring//'", is correct? ', test_passed(3)

call astring%free
acharacter = '<test> <a> <a> <a> the nested a </a> </a> </a> </test>'
astring = astring%search(in_character=acharacter, tag_start='<a>', tag_end='</a>')
test_passed(4) = astring//''=='<a> <a> <a> the nested a </a> </a> </a>'
write(stdout, "(A)") new_line('a')//'Original:  "'//acharacter//'"'
write(stdout, "(A,L1)") 'Search: "'//astring//'", is correct? ', test_passed(4)

acharacter = '<test> <first> hello </first> <sec> <sec>not the first</sec> </sec> </test>'
astring = astring%search(in_character=acharacter, tag_start='<sec>', tag_end='</sec>', istart=istart, iend=iend)
test_passed(5) = astring//''==acharacter(31:67)
write(stdout, "(A)") new_line('a')//'Original:  "'//acharacter//'"'
write(stdout, "(A,L1)") 'Search: "'//astring//'", is correct? ', test_passed(5)

write(stdout, "(A,L1)") new_line('a')//'Are all tests passed? ', all(test_passed)
stop
!-----------------------------------------------------------------------------------------------------------------------------------
endprogram search