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.
!<
!<```fortran
!< type(string) :: astring
!< logical :: test_passed(1)
!< astring = '+++ab-++cre-++cre-ab+++++'
!< test_passed(1) = astring%unique(substring='+')//''=='+ab-+cre-+cre-ab+'
!< print '(L1)', all(test_passed)
!<```
!=> T <<<
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
endfunction unique