accum_to_array Subroutine

private subroutine accum_to_array(self, out)

Materialize the accumulator into a right-sized array.

The accumulator storage is released after conversion.

Type Bound

string_accum_t

Arguments

Type IntentOptional Attributes Name
class(string_accum_t), intent(inout) :: self
type(string_t), intent(out), allocatable :: out(:)

Source Code

   subroutine accum_to_array(self, out)
      class(string_accum_t), intent(inout) :: self
      type(string_t), allocatable, intent(out) :: out(:)

      if (.not. allocated(self%a) .or. self%n <= 0) then
         allocate(out(0))
         return
      end if

      allocate(out(self%n))
      out = self%a(1:self%n)
      deallocate(self%a)
      self%n = 0
   end subroutine accum_to_array