Skip to content

Commit fb3ddd5

Browse files
committed
removed size component, changed the logic of len function, modified constructor, commented test cases
1 parent 1584eeb commit fb3ddd5

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

src/stdlib_stringlist.f90

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ module stdlib_stringlist
5151

5252
type stringlist_type
5353
private
54-
integer :: size = 0
5554
type(string_type), dimension(:), allocatable :: stringarray
5655

5756
contains
@@ -98,7 +97,6 @@ module stdlib_stringlist
9897
interface stringlist_type
9998
module procedure new_stringlist
10099
module procedure new_stringlist_carray
101-
module procedure new_stringlist_sarray
102100
end interface
103101

104102
!> Version: experimental
@@ -154,7 +152,7 @@ pure function new_stringlist()
154152
type(stringlist_type) :: new_stringlist
155153
type(string_type), dimension(0) :: sarray
156154

157-
new_stringlist = stringlist_type( 0, sarray )
155+
new_stringlist = stringlist_type( sarray )
158156

159157
end function new_stringlist
160158

@@ -174,16 +172,6 @@ pure function new_stringlist_carray( array )
174172

175173
end function new_stringlist_carray
176174

177-
!> Constructor to convert stringarray to stringlist
178-
!> Returns a new instance of type stringlist
179-
pure function new_stringlist_sarray( array )
180-
type(string_type), dimension(:), intent(in) :: array
181-
type(stringlist_type) :: new_stringlist_sarray
182-
183-
new_stringlist_sarray = stringlist_type( size(array), array )
184-
185-
end function new_stringlist_sarray
186-
187175
! constructor for stringlist_index_type:
188176

189177
!> Returns an instance of type 'stringlist_index_type' representing forward index 'idx'
@@ -455,7 +443,6 @@ end function ineq_sarray_stringlist
455443
subroutine clear_list( list )
456444
class(stringlist_type), intent(inout) :: list
457445

458-
list%size = 0
459446
if ( allocated( list%stringarray ) ) then
460447
deallocate( list%stringarray )
461448
end if
@@ -471,7 +458,10 @@ end subroutine clear_list
471458
pure integer function length_list( list )
472459
class(stringlist_type), intent(in) :: list
473460

474-
length_list = list%size
461+
length_list = 0
462+
if ( allocated( list%stringarray ) ) then
463+
length_list = size( list%stringarray )
464+
end if
475465

476466
end function length_list
477467

@@ -609,8 +599,6 @@ subroutine insert_before_empty_positions( list, idxn, positions )
609599

610600
call move_alloc( new_stringarray, list%stringarray )
611601

612-
list%size = new_len
613-
614602
end if
615603

616604
end subroutine insert_before_empty_positions

src/tests/stringlist/test_insert_at.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@ subroutine test_constructor
368368
call check( work_list == sarray, "test_constructor:&
369369
& test_case 2 work_list == sarray" )
370370

371-
write (*,*) "test_constructor: Starting test case 3!"
372-
work_list = stringlist_type( sarray )
373-
call check( work_list == carray, "test_constructor:&
374-
& test_case 3 work_list == carray" )
375-
call check( work_list == sarray, "test_constructor:&
376-
& test_case 3 work_list == sarray" )
371+
! write (*,*) "test_constructor: Starting test case 3!"
372+
! work_list = stringlist_type( sarray )
373+
! call check( work_list == carray, "test_constructor:&
374+
! & test_case 3 work_list == carray" )
375+
! call check( work_list == sarray, "test_constructor:&
376+
! & test_case 3 work_list == sarray" )
377377

378378
end subroutine test_constructor
379379

0 commit comments

Comments
 (0)