getStrings has functionality for multiple entries in a row of cumulative

searches
This commit is contained in:
Martin Diehl 2018-06-19 18:02:18 +02:00
parent 3b676af215
commit 8d5d306076
1 changed files with 57 additions and 28 deletions

View File

@ -374,11 +374,12 @@ character(len=65536) function getString(this,key,defaultVal,raw)
do while (associated(item)) do while (associated(item))
if (trim(IO_stringValue(item%string%val,item%string%pos,1)) == trim(key)) then if (trim(IO_stringValue(item%string%val,item%string%pos,1)) == trim(key)) then
found = .true. found = .true.
if (item%string%pos(1) < 2_pInt) call IO_error(143_pInt,ext_msg=key)
if (split) then if (split) then
if (item%string%pos(1) < 2_pInt) call IO_error(143_pInt,ext_msg=key)
getString = IO_StringValue(item%string%val,item%string%pos,2) getString = IO_StringValue(item%string%val,item%string%pos,2)
else else
getString = trim(item%string%val(item%string%pos(4):)) ! raw string starting a second chunk getString = trim(item%string%val(item%string%pos(4):)) ! raw string starting a second chunk
endif endif
endif endif
item => item%next item => item%next
@ -393,36 +394,64 @@ end function getString
!> @brief ... !> @brief ...
!> @details ... !> @details ...
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
function getStrings(this,key) function getStrings(this,key,defaultVal,raw)
use IO use IO
implicit none implicit none
character(len=64),dimension(:), allocatable :: getStrings character(len=65536),dimension(:), allocatable :: getStrings
class(tPartitionedStringList), intent(in) :: this class(tPartitionedStringList), intent(in) :: this
character(len=*), intent(in) :: key character(len=*), intent(in) :: key
type(tPartitionedStringList), pointer :: item character(len=65536),dimension(:), intent(in), optional :: defaultVal
character(len=64) :: str logical, intent(in), optional :: raw
integer(pInt) :: i type(tPartitionedStringList), pointer :: item
character(len=65536) :: str
integer(pInt) :: i
logical :: found, &
split, &
cumulative
cumulative = (key(1:1) == '(' .and. key(len_trim(key):len_trim(key)) == ')')
split = merge(raw,.true.,present(raw))
found = present(defaultVal)
if (present(defaultVal)) getStrings = defaultVal
item => this%next item => this%next
do do while (associated(item))
if (.not. associated(item)) then if (trim(IO_stringValue(item%string%val,item%string%pos,1)) == trim(key)) then
if (.not. allocated(getStrings)) allocate(getStrings(0),source=str) found = .true.
exit if (allocated(getStrings) .and. .not. cumulative) deallocate(getStrings)
endif if (item%string%pos(1) < 2_pInt) call IO_error(143_pInt,ext_msg=key)
if (trim(IO_stringValue(item%string%val,item%string%pos,1)) == trim(key)) then
if (item%string%pos(1) < 2) print*, "NOT WORKING" arrayAllocated: if (.not. allocated(getStrings)) then
str = IO_StringValue(item%string%val,item%string%pos,2) if (split) then
str = IO_StringValue(item%string%val,item%string%pos,2_pInt)
allocate(getStrings(1),source=str)
do i=3_pInt,item%string%pos(1)
str = IO_StringValue(item%string%val,item%string%pos,i)
getStrings = [getStrings,str]
enddo
else
str = item%string%val(item%string%pos(4):)
getStrings = [str]
endif
else arrayAllocated
if (split) then
do i=2_pInt,item%string%pos(1)
str = IO_StringValue(item%string%val,item%string%pos,i)
getStrings = [getStrings,str]
enddo
else
getStrings = [getStrings,str]
endif
endif arrayAllocated
endif
item => item%next
end do
if (.not. found) call IO_error(140_pInt,ext_msg=key)
GfortranBug86033: if (.not. allocated(getStrings)) then
allocate(getStrings(1),source=str)
else GfortranBug86033
getStrings = [getStrings,str]
endif GfortranBug86033
endif
item => item%next
end do
end function end function