Skip to content

Features ​

One type, one module ​

Everything is in the string type, exported by the stringifor module together with the numeric kinds and a few procedures:

fortran
use stringifor
type(string) :: s

s = 'Hello World'            ! assign
print '(A)', s%upper()//''   ! call a method, get a character with //

Feature map ​

AreaFeaturesWhere
The typea string of any length; arrays with elements of different lengths; assignment from characters, strings and numbers; // (a character) and .cat. (a string); ==, /=, <, <=, >=, >; defined I/OStrings and I/O
Intrinsicsadjustl, adjustr, count, index, len_trim, repeat, scan, trim, verify accept a stringStrings and I/O
Caseupper, lower, swapcase, capitalize, camelcase, snakecase, startcase; is_upper, is_lowerString Manipulation
Classesis_alpha, is_alnum, is_digit, is_xdigit, is_punct, is_spaceString Manipulation
Cleaningstrip (blanks or a set of characters), replace, unique, insert, escape, unescape, lstrip, rstrip, compact, squeeze, expand_tabs, transliterate, quote, unquoteString Manipulation
Tokenssplit (empty fields optionally kept), split_chunked, partition, join, strjoin (1D and 2D arrays)String Manipulation
Regular expressionsregex (Pike VM, linear time, Python re results): search, match, fullmatch, finditer, findall, split, sub; re_search and friendsRegular Expressions
Sortingstrsort (stable merge sort, permutation), orders strless, strless_nocase, strless_natural (file2 before file10), or your ownString Manipulation
Partsslice with a stride, reverse, reverse_words, start_with, end_with, count, index, scan, verify, search between tagsString Manipulation
Layoutfill, center, ljust, rjust, justify, len_last_wordString Manipulation
Comparingcommon_prefix, compare_version, edit_distanceString Manipulation
UTF-8is_utf8, utf8_error, codepoints, from_codepoints, to_valid_utf8: units are well-formed sequences, ill-formed bytes are kept; C escapes unescape_c, escape_c, escapes_error; XML escaping escape_xml, unescape_xml, xml_error; Unicode whitespace with unicode=.true. on is_space, strip, lstrip, rstrip, compact; byte order mark has_bom, skip_bom=, bom=; positions and widths in characters with by=SF_CHARS, byte_pos, char_pos; display width width(), by=SF_COLUMNSUnicode and UTF-8
Numbersassignment from any integer and real kind; to_number, read_number with an error status, correctly rounded without read; shortest; is_number, is_integer, is_real, is_digit; hexNumbers
Filesread_file, read_lines, read_line, write_file, write_lines, write_line, formatted or unformatted streamFiles and Paths
Pathsbasedir, basename, extension, glob, match of wildcard patterns, tempnameFiles and Paths
Encoding and coloursbase64 encode and decode; ANSI colorizeFiles and Paths

The methods summary lists every method with its arguments.

Design goals ​

GoalHow
Interchangeable with characteroverloaded assignment, //, comparisons and intrinsics: a string goes wherever a character does
Low memory consumptionone allocatable character is the only component: each element of an array is as long as its content
Safealmost every method is elemental or pure; the methods return new values and leave the string unchanged
Testedevery method carries doctests in its source; every example of these pages is compiled and run

Module architecture ​

Use only the stringifor module: it exports the type, the kinds (I1P, I2P, I4P, I8P, R4P, R8P, R16P), the character kind CK, the overloaded intrinsics, and the procedures read_file, read_lines, write_file, write_lines, glob, strjoin, strsort and its orders, the regex type and the re_* procedures.

Compiler support ​

CompilerMinimum versionStatus
GNU gfortran≥ 9.2.0Full support
Intel ifort / ifx≥ 19.0.4Full support
NVIDIA nvfortran—Builds with the _NVF macro defined, which disables the I2P kind; not regularly tested
IBM XL—Not tested
NAG—Not tested

Any feature request is welcome: open an issue on GitHub.