flibs/strings(n) 1.1 "flibs"

Name

flibs/strings - String operations

Table Of Contents

Synopsis

Description

The string_operations module implements a variety of string operations based on allocatable-length strings. The advantage is that the result can always be stored, instead of the user having to supply strings with sufficient length from the outset.

ROUTINES

The module defines routines to replace substrings, to insert or delete them and several others others. The replace subroutine may be used to replace several substrings in one call.

use string_operations

To import the definitions, use this module.

type(pair)

A derived type used by replace to define which substrings to replace by others:

    result = replace( 'RYeplace StRings', [pair('RY', 'XXXX'), pair('R', 'YY')] )

This will replace the substring "RY" by "XXXX" and any substring "R" that is left by "YY".

result = replace( input, substring, replacement, mode )

Replace the substring in the input string by the new string. The argument mode controls what substrings are exactly replaced. The result is an allocatable-length character string.

character(len=*) input

The input string which is to be edited.

character(len=*) substring

The substring which is to be replaced.

character(len=*) replacement

The string which is to replace the substring.

integer mode

The replacement mode. This argument is optional, if left out it defaults to "replace all".

  • replace_all specifies that all occurrences are to be replaced.

  • first_only specifies that only the first occurrence is to be replaced.

  • last_only specifies that only the last occurrence is to be replaced.

result = replace( input, pairs )

Replace several substrings at once. The substrings are sought one after another. The substring first in the input string that matches is replaced and then the next is sought. The procedure stops when all matches have been taken care of. Note that replaced substrings do not cause new matches.

character(len=*) input

The input string which is to be edited.

type(pair), dimension(:) pairs

The substrings to be relpaced and the strings they shoudl replaced by.

result = insert( input, pos, string )

Insert a string at a given position into a string.

character(len=*) input

The input string which is to be edited.

integer pos

The position at which the string is to be inserted. Two special values:

  • prepend specifies that new string should come at the very start.

  • append specifies that new string should be appended.

character(len=*) string

The string to be inserted.

result = delete( input, pos, length )

Delete a substring of given length.

character(len=*) input

The input string which is to be edited.

integer pos

The first position that is to be deleted.

integer length

The length of the substring to be deleted.

result = tolower( input )

Return a string with all lower case letters.

character(len=*) input

The input string which is to be edited.

result = toupper( input )

Return a string with all upper case letters.

character(len=*) input

The input string which is to be edited.

result = trimx( input, set )

Return a string with all trailing characters in the given set removed. It is an extension of the trim() intrinsic function.

character(len=*) input

The input string which is to be edited.

character(len=*) set

The set of characters that should be removed at the end.

result = trimxleft( input, set )

Return a string with all leading characters in the given set removed. It is an extension of the trim() intrinsic function.

character(len=*) input

The input string which is to be edited.

character(len=*) set

The set of characters that should be removed at the start.

call read_line_from_file( lun, text, eof )

Read a complete line from a file, regardless of the length.

integer lun

Logical unit number of the file to be read.

character(len=:), allocatable, intent(out) text

The line of text that was read or an empty string if the end of the file was reached.

logical, intent(out) eof

Indication whether the end of file was reached.