Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self | The string. |
||
character(kind=CK,len=*), | intent(in) | :: | array(1:) | Array to be joined. |
||
character(kind=CK,len=*), | intent(in), | optional | :: | sep | Separator. |
The join of array.
Return a string that is a join of an array of characters.
The join-separator is set equals to self if self has a value or it is set to a null string ''. This value can be overridden passing a custom separator.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(kind=CK,len=:), | public, | allocatable | :: | sep_ | Separator, default value. |
||
integer, | public | :: | a | Counter. |
pure function join_characters(self, array, sep) result(join)
!---------------------------------------------------------------------------------------------------------------------------------
!< Return a string that is a join of an array of characters.
!<
!< The join-separator is set equals to self if self has a value or it is set to a null string ''. This value can be overridden
!< passing a custom separator.
!---------------------------------------------------------------------------------------------------------------------------------
class(string), intent(in) :: self !< The string.
character(kind=CK, len=*), intent(in) :: array(1:) !< Array to be joined.
character(kind=CK, len=*), intent(in), optional :: sep !< Separator.
type(string) :: join !< The join of array.
character(kind=CK, len=:), allocatable :: sep_ !< Separator, default value.
integer :: a !< Counter.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (allocated(self%raw)) then
sep_ = self%raw
else
sep_ = ''
endif
if (present(sep)) sep_ = sep
join = ''
do a=2, size(array, dim=1)
if (array(a)/='') join%raw = join%raw//sep_//array(a)
enddo
if (array(1)/='') then
join%raw = array(1)//join%raw
else
join%raw = join%raw(len(sep_)+1:len(join%raw))
endif
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction join_characters