Skip to content

Commit

Permalink
fix pattern constructor due to ifort behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
perazz committed Apr 27, 2023
1 parent 2f2d4a0 commit 83a409c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/regex.f90
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,24 @@ module regex_module
module procedure re_matchp_nolength_noback
end interface regex

! Override default constructor for ifort bug
interface regex_token
module procedure pat_from_char
end interface regex_token


contains

! Construct a regex pattern from a single character
elemental type(regex_token) function pat_from_char(type,ccl) result(this)
integer, intent(in) :: type
character(kind=RCK), intent(in) :: ccl
call pat_destroy(this)
this%type = type
allocate(character(len=1,kind=RCK) :: this%ccl)
this%ccl(1:1) = ccl
end function pat_from_char

! Check that a pattern matches the expected result
logical function check_pattern(string,pattern,expected) result(success)
character(len=*,kind=RCK), intent(in) :: string
Expand Down
9 changes: 9 additions & 0 deletions test/tests.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ program tests
call add_test(test_bracket_space())
call add_test(test_end_anchor())
call add_test(test_end_anchor2())
call add_test(test_read_version())

! Test #2
call add_test(run_test2())
Expand Down Expand Up @@ -122,4 +123,12 @@ logical function test_end_anchor2() result(success)

end function test_end_anchor2

logical function test_read_version() result(success)
character(*), parameter :: &
text = 'Intel(R) MPI Library 2021.8 for Linux*Copyright Intel Corporation.ifort version 2021.8.0'

success = check_pattern(text,'\d+\.\d+\.\d+',expected="2021.8.0")

end function test_read_version

end program tests

0 comments on commit 83a409c

Please sign in to comment.