pop Subroutine

subroutine pop(buf, tok)

Remove first whitespace-separated token from buf.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: buf

Text left to split.

character(len=*), intent(out) :: tok

Removed token, blank when buf is empty.


Source Code

   subroutine pop(buf, tok)
      !! Remove first whitespace-separated token from `buf`.
      ! Arguments
      character(len=*), intent(inout) :: buf
         !! Text left to split.
      character(len=*), intent(out)   :: tok
         !! Removed token, blank when `buf` is empty.
      integer :: p
      buf = adjustl(buf)
      p = index(buf, ' ')
      if (p <= 1) then
         tok = trim(buf); buf = ''
      else
         tok = buf(1:p - 1); buf = buf(p:)
      end if
   end subroutine pop