string_builder Derived Type

type, public :: string_builder

Provides a mechanism for building strings without reallocation on each addition.


Contents


Type-Bound Procedures

generic, public :: append => sb_append_char, sb_append_string

  • private subroutine sb_append_char(this, x)

    Appends a new string to the end of the existing string.

    Arguments

    Type IntentOptional Attributes Name
    class(string_builder), intent(inout) :: this

    The string_builder object.

    character(len=*), intent(in) :: x

    The string to append.

  • private subroutine sb_append_string(this, x)

    Appends a new string to the end of the existing string.

    Arguments

    Type IntentOptional Attributes Name
    class(string_builder), intent(inout) :: this

    The string_builder object.

    type(string), intent(in) :: x

    The string to append.

procedure, public :: initialize => sb_init

  • private subroutine sb_init(this)

    Initializes the string_builder object.

    Arguments

    Type IntentOptional Attributes Name
    class(string_builder), intent(inout) :: this

    The string_builder object.

procedure, public :: length => sb_get_length

  • private pure function sb_get_length(this) result(rst)

    Returns the length of the stored string.

    Arguments

    Type IntentOptional Attributes Name
    class(string_builder), intent(in) :: this

    The string_builder object.

    Return Value integer(kind=int32)

    The lenght of the stored string.

procedure, public :: to_string => sb_to_string

  • private pure function sb_to_string(this) result(rst)

    Returns the buffer contents as a string.

    Arguments

    Type IntentOptional Attributes Name
    class(string_builder), intent(in) :: this

    The string_builder object.

    Return Value type(string)

    The resulting string.