Skip to content

Commit 6ee8a5c

Browse files
committed
removed optional replace_overlapping argument
1 parent e325c2b commit 6ee8a5c

File tree

1 file changed

+101
-16
lines changed

1 file changed

+101
-16
lines changed

src/stdlib_strings.f90

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ module stdlib_strings
8383
!> with the replacement 'replacement'
8484
!> Version: experimental
8585
interface replace_all
86-
!module procedure :: replace_all_string_string_string
87-
!module procedure :: replace_all_string_string_char
88-
!module procedure :: replace_all_string_char_string
89-
!module procedure :: replace_all_char_string_string
90-
!module procedure :: replace_all_string_char_char
91-
!module procedure :: replace_all_char_string_char
92-
!module procedure :: replace_all_char_char_string
86+
module procedure :: replace_all_string_string_string
87+
module procedure :: replace_all_string_string_char
88+
module procedure :: replace_all_string_char_string
89+
module procedure :: replace_all_char_string_string
90+
module procedure :: replace_all_string_char_char
91+
module procedure :: replace_all_char_string_char
92+
module procedure :: replace_all_char_char_string
9393
module procedure :: replace_all_char_char_char
9494
end interface replace_all
9595

@@ -513,21 +513,110 @@ pure function compute_lps(string) result(lps_array)
513513

514514
end function compute_lps
515515

516+
!> Replaces all occurrences of substring 'pattern' in the input 'string'
517+
!> with the replacement 'replacement'
518+
!> Returns a new string
519+
pure function replace_all_string_string_string(string, pattern, replacement) result(res)
520+
type(string_type), intent(in) :: string
521+
type(string_type), intent(in) :: pattern
522+
type(string_type), intent(in) :: replacement
523+
type(string_type) :: res
524+
525+
res = string_type(replace_all_char_char_char(char(string), &
526+
& char(pattern), char(replacement)))
527+
528+
end function replace_all_string_string_string
529+
530+
!> Replaces all occurrences of substring 'pattern' in the input 'string'
531+
!> with the replacement 'replacement'
532+
!> Returns a new string
533+
pure function replace_all_string_string_char(string, pattern, replacement) result(res)
534+
type(string_type), intent(in) :: string
535+
type(string_type), intent(in) :: pattern
536+
character(len=*), intent(in) :: replacement
537+
type(string_type) :: res
538+
539+
res = string_type(replace_all_char_char_char(char(string), char(pattern), replacement))
540+
541+
end function replace_all_string_string_char
542+
543+
!> Replaces all occurrences of substring 'pattern' in the input 'string'
544+
!> with the replacement 'replacement'
545+
!> Returns a new string
546+
pure function replace_all_string_char_string(string, pattern, replacement) result(res)
547+
type(string_type), intent(in) :: string
548+
character(len=*), intent(in) :: pattern
549+
type(string_type), intent(in) :: replacement
550+
type(string_type) :: res
551+
552+
res = string_type(replace_all_char_char_char(char(string), pattern, char(replacement)))
553+
554+
end function replace_all_string_char_string
555+
556+
!> Replaces all occurrences of substring 'pattern' in the input 'string'
557+
!> with the replacement 'replacement'
558+
!> Returns a new string
559+
pure function replace_all_char_string_string(string, pattern, replacement) result(res)
560+
character(len=*), intent(in) :: string
561+
type(string_type), intent(in) :: pattern
562+
type(string_type), intent(in) :: replacement
563+
character(len=:), allocatable :: res
564+
565+
res = replace_all_char_char_char(string, char(pattern), char(replacement))
566+
567+
end function replace_all_char_string_string
568+
569+
!> Replaces all occurrences of substring 'pattern' in the input 'string'
570+
!> with the replacement 'replacement'
571+
!> Returns a new string
572+
pure function replace_all_string_char_char(string, pattern, replacement) result(res)
573+
type(string_type), intent(in) :: string
574+
character(len=*), intent(in) :: pattern
575+
character(len=*), intent(in) :: replacement
576+
type(string_type) :: res
577+
578+
res = string_type(replace_all_char_char_char(char(string), pattern, replacement))
579+
580+
end function replace_all_string_char_char
581+
582+
!> Replaces all occurrences of substring 'pattern' in the input 'string'
583+
!> with the replacement 'replacement'
584+
!> Returns a new string
585+
pure function replace_all_char_string_char(string, pattern, replacement) result(res)
586+
character(len=*), intent(in) :: string
587+
type(string_type), intent(in) :: pattern
588+
character(len=*), intent(in) :: replacement
589+
character(len=:), allocatable :: res
590+
591+
res = replace_all_char_char_char(string, char(pattern), replacement)
592+
593+
end function replace_all_char_string_char
594+
595+
!> Replaces all occurrences of substring 'pattern' in the input 'string'
596+
!> with the replacement 'replacement'
597+
!> Returns a new string
598+
pure function replace_all_char_char_string(string, pattern, replacement) result(res)
599+
character(len=*), intent(in) :: string
600+
character(len=*), intent(in) :: pattern
601+
type(string_type), intent(in) :: replacement
602+
character(len=:), allocatable :: res
603+
604+
res = replace_all_char_char_char(string, pattern, char(replacement))
605+
606+
end function replace_all_char_char_string
607+
516608
!> Replaces all the occurrences of substring 'pattern' in the input 'string'
517609
!> with the replacement 'replacement'
518610
!> Returns a new string
519-
pure function replace_all_char_char_char(string, pattern, replacement, replace_overlapping) result(res)
611+
pure function replace_all_char_char_char(string, pattern, replacement) result(res)
520612
character(len=*), intent(in) :: string
521613
character(len=*), intent(in) :: pattern
522614
character(len=*), intent(in) :: replacement
523-
logical, intent(in), optional :: replace_overlapping
524615
character(:), allocatable :: res
525616
integer :: lps_array(len(pattern))
526617
integer :: s_i, p_i, last, length_string, length_pattern
527-
logical :: replace_overlapping_
528618

529619
res = ""
530-
replace_overlapping_ = optval(replace_overlapping, .false.)
531620
length_string = len(string)
532621
length_pattern = len(pattern)
533622
last = 1
@@ -544,11 +633,7 @@ pure function replace_all_char_char_char(string, pattern, replacement, replace_o
544633
& slice(string, first=last, last=s_i - length_pattern, stride=1) // &
545634
& replacement
546635
last = s_i + 1
547-
if (replace_overlapping_) then
548-
p_i = lps_array(p_i)
549-
else
550-
p_i = 0
551-
end if
636+
p_i = 0
552637
end if
553638
s_i = s_i + 1
554639
p_i = p_i + 1

0 commit comments

Comments
 (0)