accum_push Subroutine

private subroutine accum_push(self, s)

Append a string to the accumulator (grows capacity as needed).

Type Bound

string_accum_t

Arguments

Type IntentOptional Attributes Name
class(string_accum_t), intent(inout) :: self
character(len=*), intent(in) :: s

Source Code

   subroutine accum_push(self, s)
      class(string_accum_t), intent(inout) :: self
      character(len=*), intent(in) :: s
      type(string_t), allocatable :: tmp(:)
      integer :: cap

      if (len_trim(s) == 0) return

      if (.not. allocated(self%a)) then
         allocate(self%a(256))
         self%n = 0
      end if

      cap = size(self%a)
      if (self%n >= cap) then
         allocate(tmp(max(1, 2*cap)))
         if (cap > 0) tmp(1:cap) = self%a(1:cap)
         call move_alloc(tmp, self%a)
      end if

      self%n = self%n + 1
      self%a(self%n)%s = s
   end subroutine accum_push