Skip to content

flap_utils_m ​

FLAP utils.

Source: src/lib/flap_utils_m.f90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
LIST_SEPcharacter(len=*)parameterSeparator of the items of a stored list: v1||!||v2||!||.

Derived Types ​

flap_string ​

A string of any length. Arrays of it replace arrays of deferred-length strings in derived types: nvfortran 26.5 corrupts the heap when copying a type with a character(len=:), allocatable :: a(:) component (B33 of #125).

Components ​

NameTypeAttributesDescription
scharacter(len=:)allocatableThe string.

Interfaces ​

count ​

Overload intrinsic function count for counting substring occurences into strings.

Module procedures: count_substring

Subroutines ​

list_items ​

Return the items of a stored list, each as long as the whole list; an empty (blank) list has none.

Attributes: pure

fortran
subroutine list_items(list, items, n)

Arguments

NameTypeIntentAttributesDescription
listcharacter(len=*)inStored list.
itemscharacter(len=:)outallocatableItems.
ninteger(kind=I4P)outNumber of items.

Call graph

list_push ​

Append an item to a stored list (an unallocated list is empty).

Attributes: pure

fortran
subroutine list_push(list, item)

Arguments

NameTypeIntentAttributesDescription
listcharacter(len=:)inoutallocatableStored list.
itemcharacter(len=*)inItem.

Call graph

read_env ​

Read an environment variable, whatever the length of its value: the only environment lookup of the library.

Every lookup goes through here (step 0.D.2 of #125), so that ignore_env (F20) applies to all of them.

fortran
subroutine read_env(name, value, found, ignore)

Arguments

NameTypeIntentAttributesDescription
namecharacter(len=*)inName of the variable.
valuecharacter(len=:)outallocatableValue; empty when the variable is not set.
foundlogicaloutTrue if the variable is set (maybe to an empty value).
ignorelogicalinoptionalIgnore the environment: never found (ignore_env).

Call graph

read_line ​

Read a whole line of any length (non-advancing reads); a last line without line end is a line.

iostat is 0 for a line, an end-of-file code (is_iostat_end) at the end of the input, positive for a read error.

fortran
subroutine read_line(lun, line, iostat, iomsg)

Arguments

NameTypeIntentAttributesDescription
luninteger(kind=I4P)inUnit.
linecharacter(len=:)outallocatableLine.
iostatinteger(kind=I4P)outI/O status: 0, end of file, or an error.
iomsgcharacter(len=*)outoptionalI/O message of an error.

Call graph

tokenize ​

Tokenize a string in order to parse it.

@note The dummy array containing tokens must allocatable and its character elements must have the same length of the input string. If the length of the delimiter is higher than the input string one then the output tokens array is allocated with only one element set to input string.

Attributes: pure

fortran
subroutine tokenize(strin, delimiter, toks, Nt)

Arguments

NameTypeIntentAttributesDescription
strincharacter(len=*)inString to be tokenized.
delimitercharacter(len=*)inDelimiter of tokens.
tokscharacter(len=len)outallocatableTokens.
Ntinteger(kind=I4P)outoptionalNumber of tokens.

Call graph

split_command_line ​

Split a command line string into arguments, in one pass, with shell-like quoting.

Blanks and tabs separate arguments outside quotes. Text inside '...' or "..." is taken literally (both kinds, a quote of the other kind included); a quoted part is joined to the adjacent text (ab"c d"e is abc de), and a quoted empty string is an empty argument. An unterminated quote extends to the end of the string. There are no escape characters.

Attributes: pure

fortran
subroutine split_command_line(strin, toks, Nt)

Arguments

NameTypeIntentAttributesDescription
strincharacter(len=*)inCommand line string.
tokscharacter(len=len)outallocatableArguments.
Ntinteger(kind=I4P)outNumber of arguments.

Call graph

write_text ​

Write a text on a unit. The text is an argument, so a function building it (usage, signature) is evaluated before the write starts: nvfortran 26.5 loses the output of a write whose output list calls a function that does I/O itself.

fortran
subroutine write_text(lun, text)

Arguments

NameTypeIntentAttributesDescription
luninteger(kind=I4P)inUnit.
textcharacter(len=*)inText.

Call graph

csv_split ​

Split one CSV record (an RFC 4180 subset), the format of list values read from the environment (F22 of #125).

The separator is ','; a field in "..." may hold commas, and "" in it is a literal "; blanks around an unquoted field are trimmed, those inside quotes kept; a quote inside an unquoted field is kept; an empty or blank record has no field. Not to be confused with tokenize, whose trailing-token behaviour the stored lists rely on.

Attributes: pure

fortran
subroutine csv_split(record, fields, nf, error)

Arguments

NameTypeIntentAttributesDescription
recordcharacter(len=*)inCSV record.
fieldstype(flap_string)outallocatableFields, with their exact length.
nfinteger(kind=I4P)outNumber of fields.
errorinteger(kind=I4P)out0, or 1 for an unterminated quote.

Call graph

Functions ​

count_substring ​

Count the number of (non-overlapping) occurences of a substring into a string.

Attributes: elemental

Returns: integer(kind=I4P)

fortran
function count_substring(string, substring) result(No)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inString.
substringcharacter(len=*)inSubstring.

to_characters ​

Return an array of strings as a character array, each element as long as the longest string.

Attributes: pure

Returns: character(len=:)

fortran
function to_characters(strings) result(chars)

Arguments

NameTypeIntentAttributesDescription
stringstype(flap_string)inStrings.

Call graph

list_count ​

Return the number of items of a stored list; an empty (blank) list has none.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function list_count(list) result(n)

Arguments

NameTypeIntentAttributesDescription
listcharacter(len=*)inStored list.

Call graph

list_join ​

Return the items of a stored list with a separator between them.

Attributes: pure

Returns: character(len=:)

fortran
function list_join(list, sep) result(joined)

Arguments

NameTypeIntentAttributesDescription
listcharacter(len=*)inStored list.
sepcharacter(len=*)inSeparator.

Call graph

replace ​

Replace substring (only first occurrence) into a string.

Attributes: pure

Returns: character(len=:)

fortran
function replace(string, substring, restring) result(newstring)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inString to be modified.
substringcharacter(len=*)inSubstring to be replaced.
restringcharacter(len=*)inString to be inserted.

replace_all ​

Replace substring (all occurrences) into a string.

The string is scanned once from left to right, so a replacement containing the substring is not replaced again. @note Leading and trailing white spaces are stripped out.

Attributes: pure

Returns: character(len=:)

fortran
function replace_all(string, substring, restring) result(newstring)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inString to be modified.
substringcharacter(len=*)inSubstring to be replaced.
restringcharacter(len=*)inString to be inserted.

Call graph

unique ​

Reduce to one (unique) multiple (sequential) occurrences of a characters substring into a string.

For example the string ' ab-cre-cre-ab' is reduce to ' ab-cre-ab' if the substring is '-cre'. The result has the length of the input string, padded with trailing blanks.

Attributes: elemental

Returns: character(len=len)

fortran
function unique(string, substring) result(uniq)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inString to be parsed.
substringcharacter(len=*)inSubstring which multiple occurences must be reduced to one.

Call graph

upper_case ​

Convert the lower case characters of a string to upper case one.

Attributes: elemental

Returns: character(len=len)

fortran
function upper_case(string)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inString to be converted.

Call graph

fish_escape ​

Return a text for a fish single-quoted string (F15 of #125): a backslash and a quote are escaped, new lines become blanks.

Attributes: pure

Returns: character(len=:)

fortran
function fish_escape(text) result(escaped)

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)inText.

Call graph

ps_escape ​

Return a text for a PowerShell single-quoted string (F15 of #125): a quote is doubled, new lines become blanks.

Attributes: pure

Returns: character(len=:)

fortran
function ps_escape(text) result(escaped)

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)inText.

Call graph

levenshtein ​

Return the Levenshtein (edit) distance of two strings: insertions, deletions and substitutions, two-row dynamic programming, O(len(a) len(b)).

Attributes: pure

Returns: integer(kind=I4P)

fortran
function levenshtein(a, b) result(d)

Arguments

NameTypeIntentAttributesDescription
acharacter(len=*)inFirst string.
bcharacter(len=*)inSecond string.

suggestions ​

Return the "Did you mean" hint of an unknown token (F10 of #125): up to three candidates with similarity 1 - d/max(len) >= 0.6 (d the Levenshtein distance), most similar first (declaration order among equals), with click's wording: ' Did you mean "x"?' or ' (Did you mean one of: "x", "y"?)'; '' for none. Case-folded with case_insensitive.

Attributes: pure

Returns: character(len=:)

fortran
function suggestions(token, candidates, case_insensitive) result(hint)

Arguments

NameTypeIntentAttributesDescription
tokencharacter(len=*)inUnknown token.
candidatestype(flap_string)inCandidate names.
case_insensitivelogicalinCompare in any case.

Call graph

wstrip ​

Strip out leading and trailing white spaces from a string.

Attributes: pure

Returns: character(len=:)

fortran
function wstrip(string) result(newstring)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inString to be modified.

Call graph