title |
---|
string_type |
[TOC]
The stdlib_string_type
provides a derived type holding an arbitrary sequence
of characters compatible with most Fortran intrinsic character procedures as
well as operators for working with character variables and constants.
The string_type
is defined as a non-extendible derived type representing a
sequence of characters. The internal representation of the character sequence
is implementation dependent and not visible for the user of the module.
Experimental
Procedures returning string_type
instances can usually be used in elemental
context, while procedures returning scalar character values can only be
used in a pure way.
Experimental
The module defines a constructor to create an empty string type.
Creates a string instance representing an empty string.
res =
[[stdlib_string_type(module):string_type(interface)]] ()
Elemental function.
None.
The result is an instance of string_type
with zero length.
{!example/string_type/example_constructor_empty.f90!}
Experimental
The module defines a constructor to create a string type from a character scalar.
Creates a string instance representing the input character scalar value. The constructor shall create an empty string if an unallocated deferred-length character variable is passed.
res =
[[stdlib_string_type(module):string_type(interface)]] (string)
Elemental function.
string
: shall be a scalar character value. It is an intent(in)
argument.
The result is an instance of string_type
.
{!example/string_type/example_constructor_scalar.f90!}
Experimental
The module defines a constructor to create a string type from an integer scalar.
res =
[[stdlib_string_type(module):string_type(interface)]] (string)
Elemental function.
val
: shall be a scalar integer value. It is an intent(in)
argument.
The result is an instance of string_type
.
{!example/string_type/example_constructor_integer.f90!}
Experimental
The module defines a constructor to create a string type from a logical scalar.
res =
[[stdlib_string_type(module):string_type(interface)]] (string)
Elemental function.
val
: shall be a scalar logical value. It is an intent(in)
argument.
The result is an instance of string_type
.
{!example/string_type/example_constructor_logical.f90!}
Experimental
The module defines an assignment operations, =
, to create a string type
from a character scalar.
Creates a string instance representing the right-hand-side character scalar value.
lhs = rhs
Elemental subroutine, assignment(=)
.
{!example/string_type/example_constructor_character.f90!}
Experimental
Returns the length of the string.
res =
[[stdlib_string_type(module):len(interface)]] (string)
Elemental function.
string
: Instance of a string_type
. This argument is intent(in)
.
The result is a default integer scalar value.
{!example/string_type/example_len.f90!}
Experimental
Returns the length of the character sequence without trailing spaces represented by the string.
res =
[[stdlib_string_type(module):len_trim(interface)]] (string)
Elemental function.
string
: Instance of a string_type
. This argument is intent(in)
.
The result is a default integer scalar value.
{!example/string_type/example_len_trim.f90!}
Experimental
Returns the character sequence hold by the string without trailing spaces
represented by a string_type
.
res =
[[stdlib_string_type(module):trim(interface)]] (string)
Elemental function.
string
: Instance of astring_type
. This argument isintent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_trim.f90!}
Experimental
Left-adjust the character sequence represented by the string. The length of the character sequence remains unchanged.
res =
[[stdlib_string_type(module):adjustl(interface)]] (string)
Elemental function.
string
: Instance of astring_type
. This argument isintent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_adjustl.f90!}
Experimental
Right-adjust the character sequence represented by the string. The length of the character sequence remains unchanged.
res =
[[stdlib_string_type(module):adjustr(interface)]] (string)
Elemental function.
string
: Instance of astring_type
. This argument isintent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_adjustr.f90!}
Experimental
Repeats the character sequence hold by the string by the number of specified copies.
res =
[[stdlib_string_type(module):repeat(interface)]] (string, ncopies)
Elemental function.
string
: Instance of astring_type
. This argument isintent(in)
.ncopies
: Integer of default type. This argument isintent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_repeat.f90!}
Experimental
Return the character sequence represented by the string.
res =
[[stdlib_string_type(module):char(interface)]] (string)
Pure function.
string
: Instance of astring_type
. This argument isintent(in)
.
The result is a scalar character value.
{!example/string_type/example_char.f90!}
Experimental
Return the character at a certain position in the string.
res =
[[stdlib_string_type(module):char(interface)]] (string, pos)
Elemental function.
string
: Instance of astring_type
. This argument isintent(in)
.pos
: Integer of default type. This argument isintent(in)
.
The result is a scalar character value.
{!example/string_type/example_char_position.f90!}
Experimental
Return a substring from the character sequence of the string.
res =
[[stdlib_string_type(module):char(interface)]] (string, start, last)
Pure function.
string
: Instance of astring_type
. This argument isintent(in)
.start
: Integer of default type. This argument isintent(in)
.last
: Integer of default type. This argument isintent(in)
.
The result is a scalar character value.
{!example/string_type/example_char_range.f90!}
Experimental
Character-to-integer conversion function.
Returns the code for the character in the first character position of the character sequence in the system's native character set.
res =
[[stdlib_string_type(module):ichar(interface)]] (string)
Elemental function.
string
: Instance of astring_type
. This argument isintent(in)
.
The result is a default integer scalar value.
{!example/string_type/example_ichar.f90!}
Experimental
Code in ASCII collating sequence.
Returns the code for the ASCII character in the first character position of the character sequences represent by the string.
res =
[[stdlib_string_type(module):iachar(interface)]] (string)
Elemental function.
string
: Instance of astring_type
. This argument isintent(in)
.
The result is a default integer scalar value.
{!example/string_type/example_iachar.f90!}
Experimental
Position of a substring within a string.
Returns the position of the start of the leftmost or rightmost occurrence of string substring in string, counting from one. If substring is not present in string, zero is returned.
res =
[[stdlib_string_type(module):index(interface)]] (string, substring[, back])
Elemental function.
string
: Either scalar character value or string type. This argument isintent(in)
.substring
: Either scalar character value or string type. This argument isintent(in)
.back
: Either absent or a scalar logical value. This argument isintent(in)
.
The result is a default integer scalar value.
{!example/string_type/example_index.f90!}
Experimental
Scans a string for the presence any of the characters in a set of characters. If back is either absent or false, this function returns the position of the leftmost character of string that is in set. If back is true, the rightmost position is returned. If no character of set is found in string, the result is zero.
res =
[[stdlib_string_type(module):scan(interface)]] (string, set[, back])
Elemental function.
string
: Either scalar character value or string type. This argument isintent(in)
.set
: Either scalar character value or string type. This argument isintent(in)
.back
: Either absent or a scalar logical value. This argument isintent(in)
.
The result is a default integer scalar value.
{!example/string_type/example_scan.f90!}
Experimental
Verifies that all the characters in string belong to the set of characters in set. If back is either absent or false, this function returns the position of the leftmost character of string that is not in set. If back is true, the rightmost position is returned. If all characters of string are found in set, the result is zero.
res =
[[stdlib_string_type(module):verify(interface)]] (string, set[, back])
Elemental function.
string
: Either scalar character value or string type. This argument isintent(in)
.set
: Either scalar character value or string type. This argument isintent(in)
.back
: Either absent or a scalar logical value. This argument isintent(in)
.
The result is a default integer scalar value.
{!example/string_type/example_verify.f90!}
Experimental
Lexically compare the order of two character sequences being greater than.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic lgt
procedure.
res =
[[stdlib_string_type(module):lgt(interface)]] (lhs, rhs)
Elemental function.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_lgt.f90!}
Experimental
Lexically compare the order of two character sequences being less than.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic llt
procedure.
res =
[[stdlib_string_type(module):llt(interface)]] (lhs, rhs)
Elemental function.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_llt.f90!}
Experimental
Lexically compare the order of two character sequences being greater than or equal.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic lge
procedure.
res =
[[stdlib_string_type(module):lge(interface)]] (lhs, rhs)
Elemental function.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_lge.f90!}
Experimental
Lexically compare the order of two character sequences being less than or equal.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic lle
procedure.
res =
[[stdlib_string_type(module):lle(interface)]] (lhs, rhs)
Elemental function.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_lle.f90!}
Experimental
Returns a new string_type instance which holds the lowercase version of the character sequence hold by the input string.
lowercase_string =
[[stdlib_string_type(module):to_lower(interface)]] (string)
Elemental function.
string
: Instance of string_type
. This argument is intent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_to_lower.f90!}
Experimental
Returns a new string_type instance which holds the uppercase version of the character sequence hold by the input string.
uppercase_string =
[[stdlib_string_type(module):to_upper(interface)]] (string)
Elemental function.
string
: Instance of string_type
. This argument is intent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_to_upper.f90!}
Experimental
Returns a new string_type instance which holds the titlecase version of the character sequence hold by the input string. Title case: First character of every word in the sentence is converted to uppercase and the rest of the characters are converted to lowercase. A word is a contiguous sequence of character(s) which consists of alphabetical character(s) and numeral(s) only and doesn't exclude any alphabetical character or numeral present next to either of its 2 ends.
titlecase_string =
[[stdlib_string_type(module):to_title(interface)]] (string)
Elemental function.
string
: Instance of string_type
. This argument is intent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_to_title.f90!}
Experimental
Returns a new string_type instance which holds the sentencecase version of the character sequence hold by the input string. Sentencecase version: The first alphabetical character of the input character sequence is transformed to uppercase unless it follows a numeral and the rest of the characters in the sequence are transformed to lowercase.
sentencecase_string =
[[stdlib_string_type(module):to_sentence(interface)]] (string)
Elemental function.
string
: Instance of string_type
. This argument is intent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_to_sentence.f90!}
Experimental
Returns a new string_type instance which holds the reversed version of the character sequence hold by the input string.
reverse_string =
[[stdlib_string_type(module):reverse(interface)]] (string)
Elemental function.
string
: Instance of string_type
. This argument is intent(in)
.
The result is a scalar string_type
value.
{!example/string_type/example_reverse.f90!}
Experimental
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 type.
This defines three procedures overloading the intrinsic operator(>)
and operator(.gt.)
.
res = lhs > rhs
res = lhs .gt. rhs
Elemental function, operator(>)
and operator(.gt.)
.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_gt.f90!}
Experimental
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 type.
This defines three procedures overloading the intrinsic operator(<)
and operator(.lt.)
.
res = lhs < rhs
res = lhs .lt. rhs
Elemental function, operator(<)
and operator(.lt.)
.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_lt.f90!}
Experimental
Compare the order of two character sequences being greater or equal.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic operator(>=)
and operator(.ge.)
.
res = lhs >= rhs
res = lhs .ge. rhs
Elemental function, operator(>=)
and operator(.ge.)
.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_ge.f90!}
Experimental
Compare the order of two character sequences being less or equal.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic operator(<=)
and operator(.le.)
.
res = lhs <= rhs
res = lhs .le. rhs
Elemental function, operator(<=)
and operator(.le.)
.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_le.f90!}
Experimental
Compare two character sequences for equality.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic operator(==)
and operator(.eq.)
.
res = lhs == rhs
res = lhs .eq. rhs
Elemental function, operator(==)
and operator(.eq.)
.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_eq.f90!}
Experimental
Compare two character sequences for inequality.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic operator(/=)
and operator(.ne.)
.
res = lhs /= rhs
res = lhs .ne. rhs
Elemental function, operator(/=)
and operator(.ne.)
.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is a default logical scalar value.
{!example/string_type/example_ne.f90!}
Experimental
Concatenate two character sequences.
The left-hand side, the right-hand side or both character sequences can
be represented by a string type.
This defines three procedures overloading the intrinsic operator(//)
.
res = lhs // rhs
Elemental function, operator(//)
.
lhs
: Either scalar character value or string type. This argument isintent(in)
.rhs
: Either scalar character value or string type. This argument isintent(in)
.
The result is an instance of string_type
.
{!example/string_type/example_cont.f90!}
Experimental
Write the character sequence hold by the string to a connected unformatted unit. The character sequences is represented by an 64 bit signed integer record, holding the length of the following character record.
write(unit, iostat=iostat, iomsg=iomsg) string
Unformatted user defined derived type output.
string
: Instance of the string type to read. This argument isintent(inout)
.unit
: Formatted unit for output. This argument isintent(in)
.iostat
: Status identifier to indicate success of output operation. This argument isintent(out)
.iomsg
: Buffer to return error message in case of failing output operation. This argument isintent(inout)
.
{!example/string_type/example_uwrite.f90!}
Experimental
Write the character sequence hold by the string to a connected formatted unit.
The current implementation is limited to list directed output and dt
formatted
output. Requesting namelist output will raise an error.
write(unit, fmt, iostat=iostat, iomsg=iomsg) string
Formatted user defined derived type output.
string
: Instance of the string type to read. This argument isintent(inout)
.unit
: Formatted unit for output. This argument isintent(in)
.iotype
: Type of formatted data transfer, has the value"LISTDIRECTED"
forfmt=*
,"NAMELIST"
for namelist output or starts with"DT"
for derived type output. This argument isintent(in)
.v_list
: Rank one array of default integer type containing the edit descriptors for derived type output. This argument isintent(in)
.iostat
: Status identifier to indicate success of output operation. This argument isintent(out)
.iomsg
: Buffer to return error message in case of failing output operation. This argument isintent(inout)
.
{!example/string_type/example_fwrite.f90!}
Experimental
Read a character sequence from a connected unformatted unit into the string. The character sequences is represented by an 64 bit signed integer record, holding the length of the following character record.
On failure the state the read variable is undefined and implementation dependent.
read(unit, iostat=iostat, iomsg=iomsg) string
Unformatted derived type input.
string
: Instance of the string type to read. This argument isintent(inout)
.unit
: Formatted unit for input. This argument isintent(in)
.iostat
: Status identifier to indicate success of input operation. This argument isintent(out)
.iomsg
: Buffer to return error message in case of failing input operation. This argument isintent(inout)
.
{!example/string_type/example_uread.f90!}
Experimental
Read a character sequence from a connected formatted unit into the string. List-directed input will retrieve the complete record into the string.
On failure the state the read variable is undefined and implementation dependent.
The current implementation is limited to list directed input.
Requesting dt
formatted input or namelist output will raise an error.
read(unit, fmt, iostat=iostat, iomsg=iomsg) string
Formatted derived type input.
string
: Instance of the string type to read. This argument isintent(inout)
.unit
: Formatted unit for input. This argument isintent(in)
.iotype
: Type of formatted data transfer, has the value"LISTDIRECTED"
forfmt=*
,"NAMELIST"
for namelist input or starts with"DT"
for derived type input. This argument isintent(in)
.v_list
: Rank one array of default integer type containing the edit descriptors for derived type input. This argument isintent(in)
.iostat
: Status identifier to indicate success of input operation. This argument isintent(out)
.iomsg
: Buffer to return error message in case of failing input operation. This argument isintent(inout)
.
{!example/string_type/example_fread.f90!}
Experimental
Moves the allocation from from
to to
, consequently deallocating from
in this process.
If from
is not allocated before execution, to
gets deallocated by the process.
An unallocated string_type
instance is equivalent to an empty string.
If from
and to
are the same variable, then from
remains unchanged.
call
[[stdlib_string_type(module):move(interface)]] (from, to)
Pure subroutine (Elemental subroutine, only when both from
and to
are type(string_type)
)
from
: Character scalar or [[stdlib_string_type(module):string_type(type)]]. This argument isintent(inout)
.to
: Character scalar or [[stdlib_string_type(module):string_type(type)]]. This argument isintent(inout)
when bothfrom
andto
aretype(string_type)
, otherwiseintent(out)
.
{!example/string_type/example_move.f90!}