@@ -603,7 +603,7 @@ subroutine insert_before_empty_positions( list, idxn, positions )
603603 ! > Not a part of public API
604604 class(stringlist_type), intent (inout ) :: list
605605 integer , intent (inout ) :: idxn
606- integer , intent (inout ) :: positions
606+ integer , intent (in ) :: positions
607607
608608 integer :: i, inew
609609 integer :: new_len, old_len
@@ -642,8 +642,6 @@ subroutine insert_before_empty_positions( list, idxn, positions )
642642
643643 list% size = new_len
644644
645- else
646- positions = 0
647645 end if
648646
649647 end subroutine insert_before_empty_positions
@@ -659,11 +657,9 @@ subroutine insert_before_string_int_impl( list, idxn, string )
659657 type (string_type), intent (in ) :: string
660658
661659 integer :: work_idxn
662- integer :: positions
663660
664661 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 )
667663
668664 list% stringarray(work_idxn) = string
669665
@@ -681,17 +677,23 @@ subroutine insert_before_stringlist_int_impl( list, idxn, slist )
681677
682678 integer :: i
683679 integer :: work_idxn, idxnew
684- integer :: positions
680+ integer :: pre_length, post_length
685681
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 ()
689686
690- do i = 1 , slist % len ( )
687+ do i = 1 , min ( work_idxn - 1 , pre_length )
691688 idxnew = work_idxn + i - 1
692689 list% stringarray(idxnew) = slist% stringarray(i)
693690 end do
694691
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+
695697 end subroutine insert_before_stringlist_int_impl
696698
697699 ! > Version: experimental
@@ -706,11 +708,9 @@ subroutine insert_before_chararray_int_impl( list, idxn, carray )
706708
707709 integer :: i
708710 integer :: work_idxn, idxnew
709- integer :: positions
710711
711712 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 ) )
714714
715715 do i = 1 , size ( carray )
716716 idxnew = work_idxn + i - 1
@@ -731,11 +731,9 @@ subroutine insert_before_stringarray_int_impl( list, idxn, sarray )
731731
732732 integer :: i
733733 integer :: work_idxn, idxnew
734- integer :: positions
735734
736735 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 ) )
739737
740738 do i = 1 , size ( sarray )
741739 idxnew = work_idxn + i - 1
@@ -759,7 +757,7 @@ pure function get_string_idx_wrap( list, idx )
759757
760758 idxn = list% to_current_idxn( idx )
761759
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
763761 if ( 1 <= idxn .and. idxn <= list% len () ) then
764762 get_string_idx_wrap = list% stringarray(idxn)
765763
0 commit comments