sanitize_source Subroutine

private elemental subroutine sanitize_source(sep, source, error)

Sanitize source.

  • Join splitted options;

Arguments

TypeIntentOptionalAttributesName
character, intent(in) :: sep

Separator of option name/value.

type(string), intent(inout) :: source

String containing option data.

integer(kind=I4P), intent(out) :: error

Error code.


Contents

Source Code


Source Code

  elemental subroutine sanitize_source(sep, source, error)
  !< Sanitize source.
  !<
  !<+ Join splitted options;
  character(*),  intent(in)    :: sep       !< Separator of option name/value.
  type(string),  intent(inout) :: source    !< String containing option data.
  integer(I4P),  intent(out)   :: error     !< Error code.
  type(string),  allocatable   :: tokens(:) !< Source tokens.
  integer(I4P)                 :: o         !< Counter.

  call source%split(tokens=tokens, sep=new_line('a'))
  if (size(tokens, dim=1) > 1) then
    do o=2, size(tokens, dim=1)
      if (tokens(o)%index(substring=sep) == 0) tokens(o-1) = tokens(o-1)//' '//tokens(o)
    enddo
  endif
  source = ''
  do o=1, size(tokens, dim=1)
    if ((tokens(o)%index(substring=sep) > 0).or.&
        (tokens(o)%index(substring='[') > 0).or.&
        (tokens(o)%index(substring=']') > 0)) source = source//tokens(o)//new_line('a')
  enddo
  source = source%slice(1, source%len()-1)
  error = 0
  endsubroutine sanitize_source