stdlib_string_class Module

Abstract base class (ABC) specification of an extendible string type to hold an arbitrary character sequence.

A minimal implementation of the string class has to provide only a setter function in form of an assignment from a fixed length character variable and getter functions for returning the whole string, a character at a certain index and a range of characters within the bounds of the character sequence.

The ABC takes care of providing the implementations for all functionality that is intrinsic to character variables in Fortran, therefore an implementation should reexport all overloaded generic interfaces from the ABC. Any string class implementation will be compatibile with the non-extendible string_type and fixed length and deferred length character variables by those means.

Implementations of the string class that are encouraged to overwrite the type bound procedures providing those functionality in the ABC with optimized algorithms suitable for their respective representation of the character sequence.

The specification of this module is available here.



Contents


Interfaces

public interface adjustl

Left-adjust the character sequence represented by the string. The length of the character sequence remains unchanged.

Read more…
  • private elemental function adjustl_object(string) result(adjusted_string)

    Left-adjust the character sequence represented by the string. The length of the character sequence remains unchanged.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value type(string_type)

public interface adjustr

Right-adjust the character sequence represented by the string. The length of the character sequence remains unchanged.

Read more…
  • private elemental function adjustr_object(string) result(adjusted_string)

    Right-adjust the character sequence represented by the string. The length of the character sequence remains unchanged.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value type(string_type)

public interface char

Return the character sequence represented by the string.

Read more…
  • private pure function char_object(string) result(character_string)

    Return the character sequence represented by the string.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value character(len=:), allocatable

  • private elemental function char_object_pos(string, pos) result(character_string)

    Return the character sequence represented by the string.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    integer, intent(in) :: pos

    Return Value character(len=1)

  • private pure function char_object_range(string, start, last) result(character_string)

    Return the character sequence represented by the string.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    integer, intent(in) :: start
    integer, intent(in) :: last

    Return Value character(len=last-start+1)

public interface iachar

Code in ASCII collating sequence.

Read more…
  • private elemental function iachar_object(string) result(ich)

    Code in ASCII collating sequence.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value integer

public interface ichar

Character-to-integer conversion function.

Read more…
  • private elemental function ichar_object(string) result(ich)

    Character-to-integer conversion function.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value integer

public interface index

Position of a substring within a string.

Read more…
  • private elemental function index_object_object(string, substring, back) result(pos)

    Position of a sequence of character within a character sequence.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    class(string_class), intent(in) :: substring
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function index_object_string(string, substring, back) result(pos)

    Position of a sequence of character within a character sequence.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    type(string_type), intent(in) :: substring
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function index_object_char(string, substring, back) result(pos)

    Position of a sequence of character within a character sequence.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    character(len=*), intent(in) :: substring
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function index_string_object(string, substring, back) result(pos)

    Position of a sequence of character within a character sequence.

    Arguments

    Type IntentOptional AttributesName
    type(string_type), intent(in) :: string
    class(string_class), intent(in) :: substring
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function index_char_object(string, substring, back) result(pos)

    Position of a sequence of character within a character sequence.

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: string
    class(string_class), intent(in) :: substring
    logical, intent(in), optional :: back

    Return Value integer

public interface len

Returns the length of the character sequence represented by the string.

Read more…
  • private elemental function len_object(string) result(length)

    Returns the length of the character sequence represented by the string.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value integer

public interface len_trim

Returns the length of the character sequence without trailing spaces represented by the string.

Read more…
  • private elemental function len_trim_object(string) result(length)

    Returns the length of the character sequence without trailing spaces represented by the string.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value integer

public interface lge

Lexically compare the order of two character sequences being greater equal, The left-hand side, the right-hand side or both character sequences can be represented by a string.

Read more…
  • private elemental function lge_object_object(lhs, rhs) result(is_lge)

    Lexically compare two character sequences for being greater or equal.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function lge_object_string(lhs, rhs) result(is_lge)

    Lexically compare two character sequences for being greater or equal.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    type(string_type), intent(in) :: rhs

    Return Value logical

  • private elemental function lge_string_object(lhs, rhs) result(is_lge)

    Lexically compare two character sequences for being greater or equal.

    Arguments

    Type IntentOptional AttributesName
    type(string_type), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function lge_object_char(lhs, rhs) result(is_lge)

    Lexically compare two character sequences for being greater or equal.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    character(len=*), intent(in) :: rhs

    Return Value logical

  • private elemental function lge_char_object(lhs, rhs) result(is_lge)

    Lexically compare two character sequences for being greater or equal.

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

public interface lgt

Lexically compare the order of two character sequences being greater, The left-hand side, the right-hand side or both character sequences can be represented by a string.

Read more…
  • private elemental function lgt_object_object(lhs, rhs) result(is_lgt)

    Lexically compare two character sequences for being greater.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function lgt_object_string(lhs, rhs) result(is_lgt)

    Lexically compare two character sequences for being greater.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    type(string_type), intent(in) :: rhs

    Return Value logical

  • private elemental function lgt_string_object(lhs, rhs) result(is_lgt)

    Lexically compare two character sequences for being greater.

    Arguments

    Type IntentOptional AttributesName
    type(string_type), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function lgt_object_char(lhs, rhs) result(is_lgt)

    Lexically compare two character sequences for being greater.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    character(len=*), intent(in) :: rhs

    Return Value logical

  • private elemental function lgt_char_object(lhs, rhs) result(is_lgt)

    Lexically compare two character sequences for being greater.

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

public interface lle

Lexically compare the order of two character sequences being less equal, The left-hand side, the right-hand side or both character sequences can be represented by a string.

Read more…
  • private elemental function lle_object_object(lhs, rhs) result(is_lle)

    Lexically compare two character sequences for being less or equal.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function lle_object_string(lhs, rhs) result(is_lle)

    Lexically compare two character sequences for being less or equal.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    type(string_type), intent(in) :: rhs

    Return Value logical

  • private elemental function lle_string_object(lhs, rhs) result(is_lle)

    Lexically compare two character sequences for being less or equal

    Arguments

    Type IntentOptional AttributesName
    type(string_type), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function lle_object_char(lhs, rhs) result(is_lle)

    Lexically compare two character sequences for being less or equal.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    character(len=*), intent(in) :: rhs

    Return Value logical

  • private elemental function lle_char_object(lhs, rhs) result(is_lle)

    Lexically compare two character sequences for being less or equal

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

public interface llt

Lexically compare the order of two character sequences being less, The left-hand side, the right-hand side or both character sequences can be represented by a string.

Read more…
  • private elemental function llt_object_object(lhs, rhs) result(is_llt)

    Lexically compare two character sequences for being less.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function llt_object_string(lhs, rhs) result(is_llt)

    Lexically compare two character sequences for being less.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    type(string_type), intent(in) :: rhs

    Return Value logical

  • private elemental function llt_string_object(lhs, rhs) result(is_llt)

    Lexically compare two character sequences for being less.

    Arguments

    Type IntentOptional AttributesName
    type(string_type), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

  • private elemental function llt_object_char(lhs, rhs) result(is_llt)

    Lexically compare two character sequences for being less.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: lhs
    character(len=*), intent(in) :: rhs

    Return Value logical

  • private elemental function llt_char_object(lhs, rhs) result(is_llt)

    Lexically compare two character sequences for being less.

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: lhs
    class(string_class), intent(in) :: rhs

    Return Value logical

public interface repeat

Repeats the character sequence hold by the string by the number of specified copies.

Read more…
  • private elemental function repeat_object(string, ncopies) result(repeated_string)

    Repeats the character sequence hold by the string by the number of specified copies.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    integer, intent(in) :: ncopies

    Return Value type(string_type)

public interface scan

Scan a string for the presence of a set of characters. Scans a string for any of the characters in a set of characters.

Read more…
  • private elemental function scan_object_object(string, set, back) result(pos)

    Scan a character sequence for any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    class(string_class), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function scan_object_string(string, set, back) result(pos)

    Scan a character sequence for any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    type(string_type), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function scan_object_char(string, set, back) result(pos)

    Scan a character sequence for any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    character(len=*), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function scan_string_object(string, set, back) result(pos)

    Scan a character sequence for any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    type(string_type), intent(in) :: string
    class(string_class), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function scan_char_object(string, set, back) result(pos)

    Scan a character sequence for any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: string
    class(string_class), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

public interface trim

Returns the character sequence hold by the string without trailing spaces.

Read more…
  • private elemental function trim_object(string) result(trimmed_string)

    Returns the character sequence hold by the string without trailing spaces.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string

    Return Value type(string_type)

public interface verify

Scan a string for the absence of a set of characters. Verifies that all the characters in string belong to the set of characters in set.

Read more…
  • private elemental function verify_object_object(string, set, back) result(pos)

    Verify a character sequence for the absence any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    class(string_class), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function verify_object_string(string, set, back) result(pos)

    Verify a character sequence for the absence any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    type(string_type), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function verify_object_char(string, set, back) result(pos)

    Verify a character sequence for the absence any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    class(string_class), intent(in) :: string
    character(len=*), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function verify_string_object(string, set, back) result(pos)

    Verify a character sequence for the absence any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    type(string_type), intent(in) :: string
    class(string_class), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer

  • private elemental function verify_char_object(string, set, back) result(pos)

    Verify a character sequence for the absence any of the characters in a set of characters.

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: string
    class(string_class), intent(in) :: set
    logical, intent(in), optional :: back

    Return Value integer


Derived Types

type, public, abstract :: string_class

Abstract base class for string objects

Type-Bound Procedures

procedure(assign_object_char_interface), public :: assign_object_char
generic, public :: assignment(=) => assign_object_char

Assign a character sequence to a string object.

generic, public :: assignment(=) => assign_object_string

Assign a string type to a string object.

generic, public :: assignment(=) => assign_object_object

Assign a string type to a string object.

procedure(get_char_interface), public :: get_char

Return the character sequence represented by the string.

procedure(get_char_pos_interface), public :: get_char_pos

Return the character sequence represented by the string.

procedure(get_char_range_interface), public :: get_char_range

Return the character sequence represented by the string.

procedure(get_int_interface), public :: get_len

Returns the length of the character sequence represented by the string.

procedure(get_int_interface), public :: get_len_trim

Returns the length of the character sequence without trailing spaces represented by the string.

generic, public :: operator(//) => concat_object_object, concat_object_string, concat_string_object, concat_object_char, concat_char_object

Compare two character sequences for inequality.

generic, public :: operator(/=) => ne_object_object, ne_object_string, ne_string_object, ne_object_char, ne_char_object

Compare two character sequences for inequality.

generic, public :: operator(<) => lt_object_object, lt_object_string, lt_string_object, lt_object_char, lt_char_object

Compare two character sequences for being less.

generic, public :: operator(<=) => le_object_object, le_object_string, le_string_object, le_object_char, le_char_object

Compare two character sequences for being less or equal.

generic, public :: operator(==) => eq_object_object, eq_object_string, eq_string_object, eq_object_char, eq_char_object

Compare two character sequences for equality.

generic, public :: operator(>) => gt_object_object, gt_object_string, gt_string_object, gt_object_char, gt_char_object

Compare two character sequences for being greater.

generic, public :: operator(>=) => ge_object_object, ge_object_string, ge_string_object, ge_object_char, ge_char_object

Compare two character sequences for being greater or equal.

generic, public :: read(formatted) => read_formatted

Read a character sequence from a connected formatted unit into the string.

generic, public :: read(unformatted) => read_unformatted

Read a character sequence from a connected unformatted unit into the string.

generic, public :: write(formatted) => write_formatted

Write the character sequence hold by the string to a connected formatted unit.

generic, public :: write(unformatted) => write_unformatted

Write the character sequence hold by the string to a connected unformatted unit.