@@ -83,13 +83,13 @@ module stdlib_strings
83
83
! > with the replacement 'replacement'
84
84
! > Version: experimental
85
85
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
93
93
module procedure :: replace_all_char_char_char
94
94
end interface replace_all
95
95
@@ -513,21 +513,110 @@ pure function compute_lps(string) result(lps_array)
513
513
514
514
end function compute_lps
515
515
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
+
516
608
! > Replaces all the occurrences of substring 'pattern' in the input 'string'
517
609
! > with the replacement 'replacement'
518
610
! > 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)
520
612
character (len=* ), intent (in ) :: string
521
613
character (len=* ), intent (in ) :: pattern
522
614
character (len=* ), intent (in ) :: replacement
523
- logical , intent (in ), optional :: replace_overlapping
524
615
character (:), allocatable :: res
525
616
integer :: lps_array(len (pattern))
526
617
integer :: s_i, p_i, last, length_string, length_pattern
527
- logical :: replace_overlapping_
528
618
529
619
res = " "
530
- replace_overlapping_ = optval(replace_overlapping, .false. )
531
620
length_string = len (string)
532
621
length_pattern = len (pattern)
533
622
last = 1
@@ -544,11 +633,7 @@ pure function replace_all_char_char_char(string, pattern, replacement, replace_o
544
633
& slice(string, first= last, last= s_i - length_pattern, stride= 1 ) // &
545
634
& replacement
546
635
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
552
637
end if
553
638
s_i = s_i + 1
554
639
p_i = p_i + 1
0 commit comments