Skip to content

Commit cc1d887

Browse files
committed
make API consistent with INDEX
1 parent cae9813 commit cc1d887

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

project/fortran-regex.depend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# depslib dependency file v1.0
2-
1671299845 source:/Users/federico/code/fortran-regex/src/regex.f90
2+
1671301959 source:/Users/federico/code/fortran-regex/src/regex.f90
33

44
1671276031 source:/Users/federico/code/fortran-regex/test/test_1.f90
55

project/regex_module.mod

-12 Bytes
Binary file not shown.

project/regex_test_1.mod

-8 Bytes
Binary file not shown.

src/regex.f90

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -370,27 +370,27 @@ logical function matchplus(p, pattern, text, it0, matchlength)
370370
end function matchplus
371371

372372
! Find matches of the given pattern in the string
373-
integer function re_match(text, pattern, length) result(index)
373+
integer function re_match(string, pattern, length) result(index)
374374
character(*,kind=RCK), intent(in) :: pattern
375-
character(*,kind=RCK), intent(in) :: text
375+
character(*,kind=RCK), intent(in) :: string
376376
integer, intent(out) :: length
377377
type (regex_op) :: command
378378

379379
command = parse_pattern(pattern)
380-
index = re_matchp(text,command,length)
380+
index = re_matchp(string,command,length)
381381

382382
end function re_match
383383

384384
! Find matches of the given pattern in the string
385-
integer function re_match_nolength(text, pattern) result(index)
385+
integer function re_match_nolength(string, pattern) result(index)
386386
character(*,kind=RCK), intent(in) :: pattern
387-
character(*,kind=RCK), intent(in) :: text
387+
character(*,kind=RCK), intent(in) :: string
388388

389389
type (regex_op) :: command
390390
integer :: length
391391

392392
command = parse_pattern(pattern)
393-
index = re_matchp(text,command,length)
393+
index = re_matchp(string,command,length)
394394

395395
end function re_match_nolength
396396

@@ -575,17 +575,17 @@ logical function pat_match(p, c) result(match)
575575

576576
end function pat_match
577577

578-
integer function re_matchp_nolength(text, pattern) result(index)
578+
integer function re_matchp_nolength(string, pattern) result(index)
579579
type(regex_op), intent(in) :: pattern
580-
character(len=*,kind=RCK), intent(in) :: text
580+
character(len=*,kind=RCK), intent(in) :: string
581581
integer :: matchlength
582-
index = re_matchp(text, pattern, matchlength)
582+
index = re_matchp(string, pattern, matchlength)
583583
end function re_matchp_nolength
584584

585585

586-
integer function re_matchp(text, pattern, matchlength) result(index)
586+
integer function re_matchp(string, pattern, matchlength) result(index)
587587
type(regex_op), intent(in) :: pattern
588-
character(len=*,kind=RCK), intent(in) :: text
588+
character(len=*,kind=RCK), intent(in) :: string
589589
integer, intent(out) :: matchlength
590590

591591
matchlength = 0
@@ -595,12 +595,12 @@ integer function re_matchp(text, pattern, matchlength) result(index)
595595
if (pattern%pattern(1)%type == BEGIN_WITH) then
596596

597597
! String must begin with this pattern
598-
index = merge(1,0,matchpattern(pattern%pattern(2:), text, matchlength))
598+
index = merge(1,0,matchpattern(pattern%pattern(2:), string, matchlength))
599599

600600
else
601601

602-
do index=1,len(text)
603-
if (matchpattern(pattern%pattern,text(index:),matchlength)) return
602+
do index=1,len(string)
603+
if (matchpattern(pattern%pattern,string(index:),matchlength)) return
604604
end do
605605

606606
index = 0
@@ -617,11 +617,6 @@ integer function re_matchp(text, pattern, matchlength) result(index)
617617
end function re_matchp
618618

619619

620-
621-
622-
623-
624-
625620
! Iterative matching
626621
logical function matchpattern(pattern, text, matchlength) result(match)
627622
class(regex_pattern), intent(in) :: pattern(:)

test/tests.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ program tests
2424

2525
! Test #3
2626
call add_test(test_invalid())
27+
call add_test(test_main())
2728

2829
if (nfailed<=0) then
2930
print *, 'SUCCESS! all tests passed.'
@@ -62,6 +63,19 @@ logical function test_invalid() result(success)
6263

6364
end function test_invalid
6465

66+
logical function test_main() result(success)
67+
use regex_module
68+
implicit none
69+
70+
integer :: idx,ln
71+
character(*), parameter :: text = 'table football'
72+
73+
idx = REGEX(string=text,pattern='foo*',length=ln);
74+
75+
! Prints "football"
76+
success = text(idx:idx+ln-1) == "foo"
77+
78+
end function test_main
6579

6680

6781

0 commit comments

Comments
 (0)