Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/string_m.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module string_m
implicit none

private
public :: string_t
public :: array_of_strings

type string_t
private
character(len=:), allocatable :: string_
contains
procedure :: string
end type

interface string_t

elemental module function construct(string) result(new_string)
implicit none
character(len=*), intent(in) :: string
type(string_t) new_string
end function

end interface

interface

pure module function string(self) result(raw_string)
implicit none
class(string_t), intent(in) :: self
character(len=:), allocatable :: raw_string
end function

pure module function array_of_strings(delimited_strings, delimiter) result(strings_array)
implicit none
character(len=*), intent(in) :: delimited_strings, delimiter
type(string_t), allocatable :: strings_array(:)
end function

end interface

end module string_m
36 changes: 36 additions & 0 deletions src/string_s.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
submodule(string_m) string_s
implicit none

contains

module procedure construct
new_string%string_ = string
end procedure

module procedure string
raw_string = self%string_
end procedure

module procedure array_of_strings
character(len=:), allocatable :: remainder, next_string
integer next_delimiter, string_end

remainder = trim(adjustl(delimited_strings))
allocate(strings_array(0))

do
next_delimiter = index(remainder, delimiter)
string_end = merge(len(remainder), next_delimiter-1, next_delimiter==0)
next_string = trim(adjustl(remainder(:string_end)))
if (len(next_string)==0) exit
strings_array = [strings_array, string_t(next_string)]
if (next_delimiter==0) then
remainder = ""
else
remainder = trim(adjustl(remainder(next_delimiter+1:)))
end if
end do

end procedure

end submodule string_s