@@ -16,6 +16,7 @@ module stdlib_string_type
1616 use stdlib_ascii, only: to_lower_ => to_lower, to_upper_ => to_upper, &
1717 & to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse
1818 use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
19+ use stdlib_optval, only: optval
1920 implicit none
2021 private
2122
@@ -569,11 +570,7 @@ contains
569570 logical, intent(in), optional :: back
570571 integer :: pos
571572
572- if (present(back)) then
573- pos = index(maybe(string), maybe(substring), back)
574- else
575- pos = index(maybe(string), maybe(substring), .false.)
576- end if
573+ pos = index(maybe(string), maybe(substring), optval(back, .false.))
577574
578575 end function index_string_string
579576
@@ -585,11 +582,7 @@ contains
585582 logical, intent(in), optional :: back
586583 integer :: pos
587584
588- if (present(back)) then
589- pos = index(maybe(string), substring, back)
590- else
591- pos = index(maybe(string), substring, .false.)
592- end if
585+ pos = index(maybe(string), substring, optval(back, .false.))
593586
594587 end function index_string_char
595588
@@ -601,11 +594,7 @@ contains
601594 logical, intent(in), optional :: back
602595 integer :: pos
603596
604- if (present(back)) then
605- pos = index(string, maybe(substring), back)
606- else
607- pos = index(string, maybe(substring), .false.)
608- end if
597+ pos = index(string, maybe(substring), optval(back, .false.))
609598
610599 end function index_char_string
611600
@@ -619,11 +608,7 @@ contains
619608 logical, intent(in), optional :: back
620609 integer :: pos
621610
622- if (present(back)) then
623- pos = scan(maybe(string), maybe(set), back)
624- else
625- pos = scan(maybe(string), maybe(set), .false.)
626- end if
611+ pos = scan(maybe(string), maybe(set), optval(back, .false.))
627612
628613 end function scan_string_string
629614
@@ -635,11 +620,7 @@ contains
635620 logical, intent(in), optional :: back
636621 integer :: pos
637622
638- if (present(back)) then
639- pos = scan(maybe(string), set, back)
640- else
641- pos = scan(maybe(string), set, .false.)
642- end if
623+ pos = scan(maybe(string), set, optval(back, .false.))
643624
644625 end function scan_string_char
645626
@@ -651,11 +632,7 @@ contains
651632 logical, intent(in), optional :: back
652633 integer :: pos
653634
654- if (present(back)) then
655- pos = scan(string, maybe(set), back)
656- else
657- pos = scan(string, maybe(set), .false.)
658- end if
635+ pos = scan(string, maybe(set), optval(back, .false.))
659636
660637 end function scan_char_string
661638
@@ -669,11 +646,7 @@ contains
669646 logical, intent(in), optional :: back
670647 integer :: pos
671648
672- if (present(back)) then
673- pos = verify(maybe(string), maybe(set), back)
674- else
675- pos = verify(maybe(string), maybe(set), .false.)
676- end if
649+ pos = verify(maybe(string), maybe(set), optval(back, .false.))
677650
678651 end function verify_string_string
679652
@@ -686,11 +659,7 @@ contains
686659 logical, intent(in), optional :: back
687660 integer :: pos
688661
689- if (present(back)) then
690- pos = verify(maybe(string), set, back)
691- else
692- pos = verify(maybe(string), set, .false.)
693- end if
662+ pos = verify(maybe(string), set, optval(back, .false.))
694663
695664 end function verify_string_char
696665
@@ -703,11 +672,7 @@ contains
703672 logical, intent(in), optional :: back
704673 integer :: pos
705674
706- if (present(back)) then
707- pos = verify(string, maybe(set), back)
708- else
709- pos = verify(string, maybe(set), .false.)
710- end if
675+ pos = verify(string, maybe(set), optval(back, .false.))
711676
712677 end function verify_char_string
713678
0 commit comments