@@ -603,7 +603,7 @@ subroutine insert_before_empty_positions( list, idxn, positions )
603
603
! > Not a part of public API
604
604
class(stringlist_type), intent (inout ) :: list
605
605
integer , intent (inout ) :: idxn
606
- integer , intent (inout ) :: positions
606
+ integer , intent (in ) :: positions
607
607
608
608
integer :: i, inew
609
609
integer :: new_len, old_len
@@ -642,8 +642,6 @@ subroutine insert_before_empty_positions( list, idxn, positions )
642
642
643
643
list% size = new_len
644
644
645
- else
646
- positions = 0
647
645
end if
648
646
649
647
end subroutine insert_before_empty_positions
@@ -659,11 +657,9 @@ subroutine insert_before_string_int_impl( list, idxn, string )
659
657
type (string_type), intent (in ) :: string
660
658
661
659
integer :: work_idxn
662
- integer :: positions
663
660
664
661
work_idxn = idxn
665
- positions = 1
666
- call insert_before_empty_positions( list, work_idxn, positions )
662
+ call insert_before_empty_positions( list, work_idxn, 1 )
667
663
668
664
list% stringarray(work_idxn) = string
669
665
@@ -681,17 +677,23 @@ subroutine insert_before_stringlist_int_impl( list, idxn, slist )
681
677
682
678
integer :: i
683
679
integer :: work_idxn, idxnew
684
- integer :: positions
680
+ integer :: pre_length, post_length
685
681
686
- work_idxn = idxn
687
- positions = slist% len ()
688
- call insert_before_empty_positions( list, work_idxn, positions )
682
+ work_idxn = idxn
683
+ pre_length = slist% len ()
684
+ call insert_before_empty_positions( list, work_idxn, pre_length )
685
+ post_length = slist% len ()
689
686
690
- do i = 1 , slist % len ( )
687
+ do i = 1 , min ( work_idxn - 1 , pre_length )
691
688
idxnew = work_idxn + i - 1
692
689
list% stringarray(idxnew) = slist% stringarray(i)
693
690
end do
694
691
692
+ do i = work_idxn + post_length - pre_length, post_length
693
+ idxnew = work_idxn + i - post_length + pre_length - 1
694
+ list% stringarray(idxnew) = slist% stringarray(i)
695
+ end do
696
+
695
697
end subroutine insert_before_stringlist_int_impl
696
698
697
699
! > Version: experimental
@@ -706,11 +708,9 @@ subroutine insert_before_chararray_int_impl( list, idxn, carray )
706
708
707
709
integer :: i
708
710
integer :: work_idxn, idxnew
709
- integer :: positions
710
711
711
712
work_idxn = idxn
712
- positions = size ( carray )
713
- call insert_before_empty_positions( list, work_idxn, positions )
713
+ call insert_before_empty_positions( list, work_idxn, size ( carray ) )
714
714
715
715
do i = 1 , size ( carray )
716
716
idxnew = work_idxn + i - 1
@@ -731,11 +731,9 @@ subroutine insert_before_stringarray_int_impl( list, idxn, sarray )
731
731
732
732
integer :: i
733
733
integer :: work_idxn, idxnew
734
- integer :: positions
735
734
736
735
work_idxn = idxn
737
- positions = size ( sarray )
738
- call insert_before_empty_positions( list, work_idxn, positions )
736
+ call insert_before_empty_positions( list, work_idxn, size ( sarray ) )
739
737
740
738
do i = 1 , size ( sarray )
741
739
idxnew = work_idxn + i - 1
@@ -759,7 +757,7 @@ pure function get_string_idx_wrap( list, idx )
759
757
760
758
idxn = list% to_current_idxn( idx )
761
759
762
- ! - if the index is out of bounds, return a string_type equivalent to empty string
760
+ ! if the index is out of bounds, return a string_type equivalent to empty string
763
761
if ( 1 <= idxn .and. idxn <= list% len () ) then
764
762
get_string_idx_wrap = list% stringarray(idxn)
765
763
0 commit comments