Skip to content

Commit 4b69e3d

Browse files
committed
added constructor for string array and its test cases
1 parent f0a668c commit 4b69e3d

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Diff for: src/stdlib_stringlist_type.f90

+12-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ module stdlib_stringlist_type
9797
interface stringlist_type
9898
module procedure new_stringlist
9999
module procedure new_stringlist_carray
100+
module procedure new_stringlist_sarray
100101
end interface
101102

102103
!> Version: experimental
@@ -150,9 +151,6 @@ module stdlib_stringlist_type
150151
!> Returns a new instance of type stringlist
151152
pure function new_stringlist()
152153
type(stringlist_type) :: new_stringlist
153-
type(string_type), dimension(0) :: sarray
154-
155-
new_stringlist = stringlist_type( sarray )
156154

157155
end function new_stringlist
158156

@@ -172,6 +170,17 @@ pure function new_stringlist_carray( array )
172170

173171
end function new_stringlist_carray
174172

173+
!> Constructor to convert stringarray to stringlist
174+
!> Returns a new instance of type stringlist
175+
pure function new_stringlist_sarray( array )
176+
type(string_type), dimension(:), intent(in) :: array
177+
type(stringlist_type) :: new_stringlist_sarray
178+
179+
new_stringlist_sarray = stringlist_type()
180+
new_stringlist_sarray%stringarray = array
181+
182+
end function new_stringlist_sarray
183+
175184
! constructor for stringlist_index_type:
176185

177186
!> Returns an instance of type 'stringlist_index_type' representing forward index 'idx'

Diff for: src/tests/stringlist/test_insert_at.f90

+6-6
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ subroutine test_constructor
342342
call check( work_list == sarray, "test_constructor:&
343343
& test_case 2 work_list == sarray" )
344344

345-
! write (*,*) "test_constructor: Starting test case 3!"
346-
! work_list = stringlist_type( sarray )
347-
! call check( work_list == carray, "test_constructor:&
348-
! & test_case 3 work_list == carray" )
349-
! call check( work_list == sarray, "test_constructor:&
350-
! & test_case 3 work_list == sarray" )
345+
write (*,*) "test_constructor: Starting test case 3!"
346+
work_list = stringlist_type( sarray )
347+
call check( work_list == carray, "test_constructor:&
348+
& test_case 3 work_list == carray" )
349+
call check( work_list == sarray, "test_constructor:&
350+
& test_case 3 work_list == sarray" )
351351

352352
end subroutine test_constructor
353353

0 commit comments

Comments
 (0)