Loading...
Searching...
No Matches
string Type Reference

Inherited by macro.

Definition

Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character array.

Examples

type(string) :: s
s = 'foo'

Constructors

Initializes a new instance of the string class

string(character(:))

type(string) function string(character(:) chars) 
Parameters
[in]chars

Examples

type(string) :: s
s = string('foo')
Returns
The constructed string object.

Remarks

The string implementation proposed here is kept at the bare minimum of what is required by the library. There are many other implementations that can be found.

Definition at line 107 of file string.f90.


The documentation for this type was generated from the following file:

Variables

character(:), allocatable chars
 Variable length character array.
 

Methods

◆ assignment() [1/2]

generic, public assignment ( class(string), intent(inout) lhs,
character(*), intent(in) rhs )

Assignment overloading. Assign a character array to a string.

Parameters
[in,out]lhsstring
[in]rhscharacter(*)

Examples

type(string) :: s
s = 'foo'

Remarks

Definition at line 118 of file string.f90.

◆ assignment() [2/2]

generic, public assignment ( character(:), intent(inout), allocatable lhs,
class(string), intent(in) rhs )

Assignment overloading. Assign a string to a character array.

Parameters
[in,out]lhscharacter(:), allocatable
[in]rhsstring

Examples

type(string) :: s
character(:), allocatable :: c
s = 'foo'
c = s
! the value of c is now 'foo'

Remarks

Definition at line 118 of file string.f90.

◆ formatted()

public formatted ( class(string), intent(in) dtv,
integer, intent(in) unit,
character(*), intent(in) iotype,
integer, dimension(:), intent(in) v_list,
integer, intent(out) iostat,
character(*), intent(inout) iomsg )

Formatted output procedure for user-defined type string (UDTIO) This procedure is called automatically when a formatted WRITE statement is used with a variable of type string (when using the DT edit descriptor or default formatted output for the type).

It writes the content of the string component dtvchars using a simple A format. If the string is not allocated, an empty string is written.

Parameters
[in]dtvThe string object to be written (polymorphic dummy argument)
[in]unitFortran logical unit number
[in]iotypeString describing the edit descriptor ('DT' + optional string)
[in]v_listInteger array containing the values from the DT edit descriptor (v_list is empty if no parentheses were used after DT)
[out]iostatI/O status code (0 = success, positive = error, negative = end-of-file/end-of-record)
[in,out]iomsgMessage describing the I/O error (if any)

Note

  • This implementation ignores iotype and v_list parameters → the same simple character output is always performed
  • The procedure always uses format (A)
  • Empty (not allocated) string is written as empty line (zero characters)

Warning This is a minimal implementation of UDTIO formatted output. More sophisticated versions could:

  • respect iotype (DT"..." or LISTDIRECTED)
  • use v_list for width/precision control
  • add quotation marks, escaping, etc.

Examples

type(string) :: s
call s%set()
write(*, *) s ! may call write_formatted (depending on compiler)
write(*, '(DT)') s ! explicitly calls write_formatted

Remarks

Definition at line 123 of file string.f90.

◆ operator() [1/3]

generic, public operator ( class(string), intent(in) lhs,
type(string), intent(in) rhs )

Equality comparison between two string objects.

Parameters
[in]lhsleft-hand side
[in]rhsright-hand side
Returns
.true. if the strings are equal, .false. otherwise.

Remarks

Definition at line 120 of file string.f90.

◆ operator() [2/3]

generic, public operator ( class(string), intent(in) lhs,
character(*), intent(in) rhs )

Equality comparison between string and character expression.

Parameters
[in]lhsstring
[in]rhscharacter expression
Returns
.true. if equal, .false. otherwise.

Remarks

Definition at line 120 of file string.f90.

◆ operator() [3/3]

generic, public operator ( character(*), intent(in) lhs,
class(string), intent(in) rhs )

Equality comparison (reversed) between character expression and string.

Parameters
[in]lhscharacter expression
[in]rhsstring
Returns
.true. if equal, .false. otherwise.

Remarks

Definition at line 120 of file string.f90.

◆ write()

generic, public write

Definition at line 123 of file string.f90.