Append str to the string, doubling the storage when it is full.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(string_builder_t), | intent(inout) | :: | self |
the builder |
||
| character(len=*), | intent(in) | :: | str |
the piece to append |
pure subroutine builder_append(self, str) !! Append `str` to the string, doubling the storage when it is full. class(string_builder_t), intent(inout) :: self !! the builder character(len=*), intent(in) :: str !! the piece to append character(len=:), allocatable :: tmp if (len(str) == 0) return if (.not. allocated(self%buf)) allocate (character(len=max(256, len(str))) :: self%buf) if (self%n + len(str) > len(self%buf)) then allocate (character(len=max(2*len(self%buf), self%n + len(str))) :: tmp) tmp(1:self%n) = self%buf(1:self%n) call move_alloc(tmp, self%buf) end if self%buf(self%n + 1:self%n + len(str)) = str self%n = self%n + len(str) end subroutine builder_append