escape Function

private elemental function escape(self, to_escape, esc) result(escaped)

Arguments

Type IntentOptional AttributesName
class(string), intent(in) :: self

The string.

character(kind=CK,len=1), intent(in) :: to_escape

Character to be escaped.

character(kind=CK,len=*), intent(in), optional :: esc

Character used to escape.

Return Value type(string)

Escaped string.

Description

Escape backslashes (or custom escape character).


Variables

TypeVisibility AttributesNameInitial
character(kind=CK,len=:), public, allocatable:: esc_

Character to escape, local variable.

integer, public :: c

Character counter.


Source Code

  elemental function escape(self, to_escape, esc) result(escaped)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Escape backslashes (or custom escape character).
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string),             intent(in)           :: self      !< The string.
  character(kind=CK, len=1), intent(in)           :: to_escape !< Character to be escaped.
  character(kind=CK, len=*), intent(in), optional :: esc       !< Character used to escape.
  type(string)                                    :: escaped   !< Escaped string.
  character(kind=CK, len=:), allocatable          :: esc_      !< Character to escape, local variable.
  integer                                         :: c         !< Character counter.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (allocated(self%raw)) then
    esc_ = BACKSLASH ; if (present(esc)) esc_ = esc
    escaped%raw = ''
    do c=1, len(self%raw)
      if (self%raw(c:c)==to_escape) then
        escaped%raw = escaped%raw//esc_//to_escape
      else
        escaped%raw = escaped%raw//self%raw(c:c)
      endif
    enddo
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction escape