/M_strings

Fortran string manipulations

Primary LanguageFortranThe UnlicenseUnlicense

string

Name

M_strings and M_strings__oop - Fortran modules for processing strings

Description

The M_strings(3fm) module is a collection of Fortran procedures that supplement the built-in intrinsic string routines. Routines for parsing, tokenizing, changing case, substituting new strings for substrings, locating strings with simple wildcard expressions, removing tabs and line terminators as well as other string manipulations are included.

M_strings_oop(3fm) is a companion module that provides an OOP interface to the M_strings module.

Note there are some procedures with overlapping function that were all initially gathered here that have varying performance and robustness that may be consolidated at some point.

Synopsis

grouping page description
INTRO:OOPSM_strings__oop OOP Fortran string module
INTROM_strings Fortran string module
ARRAYbundle return up to twenty strings of arbitrary length as an array (LICENSE:PD)
ARRAYc2s convert C string pointer to Fortran character string (LICENSE:PD)
ARRAYs2c convert character variable to array of characters with last element set to null (LICENSE:PD)
ARRAYswitch converts between CHARACTER scalar and array of single characters (LICENSE:PD)
BASEbase convert whole number string in base [2-36] to string in alternate base [2-36] (LICENSE:PD)
BASEbase2 convert whole number to string in base 2 (LICENSE:PD)
BASEcodebase convert whole number in base 10 to string in base [2-36] (LICENSE:PD)
BASEdecodebase convert whole number string in base [2-36] to base 10 number (LICENSE:PD)
CASElower changes a string to lowercase over specified range (LICENSE:PD)
CASElower_quoted elemental function converts string to lowercase skipping strings quoted per Fortran syntax rules (LICENSE:PD)
CASEupper changes a string to uppercase (LICENSE:PD)
CASEupper_quoted elemental function converts string to uppercase skipping strings quoted per Fortran syntax rules (LICENSE:PD)
COMPAREends_with test if string ends with specified suffix(es) (LICENSE:PD)
COMPAREfortran_name test if string meets criteria for being a fortran name (LICENSE:PD)
COMPAREglob compare given string for match to a pattern which may contain globbing wildcard characters (LICENSE:PD)
COMPAREisalnum test membership in subsets of ASCII set (LICENSE:PD)
COMPAREisalpha returns .true. if character is a letter and .false. otherwise (LICENSE:PD)
COMPAREisascii returns .true. if the character is in the range char(0) to char(256) (LICENSE:PD)
COMPAREisblank returns .true. if character is a blank character (space or horizontal tab). (LICENSE:PD)
COMPAREiscntrl returns .true. if character is a delete character or ordinary control character (LICENSE:PD)
COMPAREisdigit returns .true. if character is a digit (0, 1, ..., 9) and .false. otherwise (LICENSE:PD)
COMPAREisgraph returns .true. if character is a printable character except a space is considered non-printable (LICENSE:PD)
COMPAREislower returns .true. if character is a miniscule letter (a-z) (LICENSE:PD)
COMPAREisprint returns .true. if character is an ASCII printable character (LICENSE:PD)
COMPAREispunct returns .true. if character is a printable punctuation character (LICENSE:PD)
COMPAREisspace returns .true. if character is a null, space, tab, carriage return, new line, vertical tab, or formfeed (LICENSE:PD)
COMPAREisupper returns .true. if character is an uppercase letter (A-Z) (LICENSE:PD)
COMPAREisxdigit returns .true. if character is a hexadecimal digit (0-9, a-f, or A-F). (LICENSE:PD)
COMPARElongest_common_substring function that returns the longest common substring of two strings.
DESCRIBEdescribe returns a string describing the name of a single character (LICENSE:PD)
DESCRIBEedit_distance returns a naive edit distance using the Levenshtein distance algorithm (LICENSE:PD)
EDITINGchange change old string to new string with a directive like a line editor (LICENSE:PD)
EDITINGjoin append CHARACTER variable array into a single CHARACTER variable with specified separator (LICENSE:PD)
EDITINGmodif emulate the MODIFY command from the line editor XEDIT (LICENSE:PD)
EDITINGreplace function replaces one substring for another in string (LICENSE:PD)
EDITINGreverse Return a string reversed (LICENSE:PD)
EDITINGsqueeze delete adjacent duplicate occurrences of a character from a string (LICENSE:PD)
EDITINGsubstitute subroutine globally substitutes one substring for another in string (LICENSE:PD)
EDITINGtransliterate replace characters from old set with new set (LICENSE:PD)
ENCODEdecode_base64 decode data from base64 encoding as defined in RFC-4648 (LICENSE:MIT)
ENCODEencode_base64 encode data using base64 encoding as defined in RFC-4648 (LICENSE:MIT)
ENCODEpercent_decode percent-decode strings and character arrays (LICENSE:ISC)
ENCODEpercent_encode percent-encode strings and character arrays (LICENSE:PD)
ENCODErotate13 apply trivial ROT13 encryption to a string (LICENSE:PD)
LENGTHcpad convert to a cropped string and then centers the string to specified length (LICENSE:PD)
LENGTHlen_white get length of string trimmed of whitespace. (LICENSE:PD)
LENGTHlenset return string trimmed or padded to specified length (LICENSE:PD)
LENGTHlpad convert to a cropped string and then blank-pad on the left to requested length (LICENSE:PD)
LENGTHmerge_str pads strings to same length and then calls MERGE(3f) (LICENSE:PD)
LENGTHpad return string padded to at least specified length (LICENSE:PD)
LENGTHrpad convert to a string and pad on the right to requested length (LICENSE:PD)
LENGTHstretch return string padded to at least specified length (LICENSE:PD)
LENGTHzpad pad a string on the left with zeros to specified length (LICENSE:PD)
NONALPHAdilate function to expand tab characters (LICENSE:PD)
NONALPHAexpand expand C-like escape sequences (LICENSE:PD)
NONALPHAnoesc convert non-printable characters to a space (LICENSE:PD)
NONALPHAnotabs expand tab characters (LICENSE:PD)
NONALPHAvisible expand a string to control and meta-control representations (LICENSE:PD)
NUMERIClistout expand a list of numbers where negative numbers denote range ends (1 -10 means 1 thru 10) (LICENSE:PD)
QUOTESmatching_delimiter find position of matching delimiter (LICENSE:PD)
QUOTESquote add quotes to string as if written with list-directed output (LICENSE:PD)
QUOTESunquote remove quotes from string as if read with list-directed input (LICENSE:PD)
TOKENSchomp Tokenize a string, consuming it one token per call (LICENSE:PD)
TOKENSdelim parse a string and store tokens into an array (LICENSE:PD)
TOKENSfind_field parse a string into tokens (LICENSE:MIT)
TOKENSparagraph break a long line into a paragraph (LICENSE:PD)
TOKENSsep function to parse string into an array using specified delimiters (LICENSE:PD)
TOKENSslice parse string into an array using specified delimiters (LICENSE:PD)
TOKENSsplit parse string into an array using specified delimiters (LICENSE:PD)
TOKENSsplit2020 parse a string into tokens using proposed f2023 method (LICENSE:PD)
TOKENSstrtok Tokenize a string (LICENSE:PD)
TYPEatoi function returns a 32-bit integer value from a string (LICENSE:PD)
TYPEatol function returns a 64-bit integer value from a string (LICENSE:PD)
TYPEaton function returns argument as a numeric value from a string (LICENSE:PD)
TYPEdble overloads DBLE(3f) so it can handle character arguments (LICENSE:PD)
TYPEfmt convert any intrinsic to a string using specified format (LICENSE:PD)
TYPEgetvals read arbitrary number of REAL values from a character variable up to size of VALUES() array (LICENSE:PD)
TYPEint overloads INT(3f) so it can handle character arguments (LICENSE:PD)
TYPEisnumber determine if a string represents a number (LICENSE:PD)
TYPEnint overloads NINT(3f) so it can handle character arguments (LICENSE:PD)
TYPEreal overloads REAL(3f) so it can handle character arguments (LICENSE:PD)
TYPEs2v function returns doubleprecision numeric value from a string (LICENSE:PD)
TYPEs2vs given a string representing numbers return a numeric array (LICENSE:PD)
TYPEstr converts multiple values to a (CSV) string (LICENSE:PD)
TYPEstring_to_value subroutine returns numeric value from string (LICENSE:PD)
TYPEstring_to_values read a string representing numbers into a numeric array (LICENSE:PD)
TYPEv2s return numeric string from a numeric value (LICENSE:PD)
TYPEvalue_to_string return numeric string from a numeric value (LICENSE:PD)
WHITESPACEadjustc center text (LICENSE:PD)
WHITESPACEclip trim leading and trailing blanks or set of characters from a string (LICENSE:PD)
WHITESPACEcompact converts contiguous whitespace to a single character (or nothing) (LICENSE:PD)
WHITESPACEcrop trim leading and trailing blanks and control characters from a string (LICENSE:PD)
WHITESPACEindent count number of leading spaces in a string (LICENSE:PD)
WHITESPACEnospace remove all whitespace from input string (LICENSE:PD)

Intrinsics

The M_strings(3fm) module supplements and works in combination with the Fortran built-in intrinsics. Standard Fortran lets you access the characters in a string using ranges much like they are character arrays assignment, comparisons with standard operators, supports dynamically allocatable strings and supports concatenation using the // operator:

 adjustl             Left adjust a string
 adjustr             Right adjust a string
 index               Position of a substring within a string
 repeat              Repeated string concatenation
 scan                Scan a string for the presence of a set of characters
 trim                Remove trailing blank characters of a string
 verify              Scan a string for the absence of a set of characters
 len                 It returns the length of a character string
 achar               converts an integer into a character
 iachar              converts a character into an integer
 len_trim            finds length of string with trailing spaces ignored
 new_line            Newline character
 selected_char_kind  Choose character kind
 lge                 Lexical greater than or equal
 lgt                 Lexical greater than
 lle                 Lexical less than or equal
 llt                 Lexical less than

gmake

Download and Build with make(1)

Just download the github repository, enter the src/ directory and run make:

 git clone https://github.com/urbanjost/M_strings.git
 cd M_strings/src
 # change Makefile if not using one of the listed compilers

 # for gfortran
 make clean
 make F90=gfortran gfortran

 # for ifort
 make clean
 make F90=ifort ifort

 # for nvfortran
 make clean
 make F90=nvfortran nvfortran

 # optionally
 make test # run the unit tests
 make run  # run all the demo programs from the man-pages
 make help # see other developer options

This will compile the M_strings(3f) module and optionally build all the example programs from the document pages in the example/ sub-directory and run the unit tests.


fpm

Download and Build with fpm(1)

Alternatively, download the github repository and build it with fpm ( as described at Fortran Package Manager )

     git clone https://github.com/urbanjost/M_strings.git
     cd M_strings
     fpm build
     fpm test  # run unit tests

or just list it as a dependency in your fpm.toml project file.

     [dependencies]
     M_strings        = { git = "https://github.com/urbanjost/M_strings.git" ,tag="v1.0.1"}

Note that M_strings.f90 is registered at the fpm(1) registry


docs

Documentation

User

There are descriptions of each procedures in the style of man-pages in three formats:

  • An index to the HTML versions of the man-pages.

  • A single page (that uses javascript) combining all the HTML descriptions of the man-pages for easy searching and printing: BOOK_M_strings.

  • man-pages man-page archives for installation on GNU/Linux, Unix and CygWin platforms:

  • CHANGELOG provides a history of significant changes

Developer


demos

Demo Programs

Each man-page includes a working example program. These and additional examples are included in the example/ directory.

See Also

  • M_match Fortran module for Basic Regular Expressions (LICENSE:PD)
  • M_regex Fortran interface to POSIX 1003.2 regular expression library using ISO_C_BINDING.