Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self | The string. |
||
character(kind=CK,len=*), | intent(in), | optional | :: | substring | Substring which multiple occurences must be reduced to one. |
String parsed.
Reduce to one (unique) multiple (sequential) occurrences of a substring into a string.
For example the string ' ab-cre-cre-ab' is reduce to 'ab-cre-ab' if the substring is '-cre'.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(kind=CK,len=:), | public, | allocatable | :: | substring_ | Substring, default value. |
elemental function unique(self, substring) result(uniq)
!---------------------------------------------------------------------------------------------------------------------------------
!< Reduce to one (unique) multiple (sequential) occurrences of a substring into a string.
!<
!< For example the string ' ab-cre-cre-ab' is reduce to 'ab-cre-ab' if the substring is '-cre'.
!< @note Eventual multiple trailing white space are not reduced to one occurrence.
!---------------------------------------------------------------------------------------------------------------------------------
class(string), intent(in) :: self !< The string.
character(kind=CK, len=*), intent(in), optional :: substring !< Substring which multiple occurences must be reduced to one.
character(kind=CK, len=:), allocatable :: substring_ !< Substring, default value.
type(string) :: uniq !< String parsed.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (allocated(self%raw)) then
substring_ = SPACE ; if (present(substring)) substring_ = substring
uniq = self
do
if (.not.uniq%index(repeat(substring_, 2))>0) exit
uniq = uniq%replace(old=repeat(substring_, 2), new=substring_)
enddo
endif
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction unique