Description
Let's start a discussion on routines for string handling and manipulation. The thread over at j3-fortran already collected some ideas:
- split - given a separator, splits the string into some form of array
- upper/lower - convert a character string to all upper/lower case
The discussion also mentioned the proposed iso_varying_string
module, which was supposed to include some string routines. I found three distinct implementations of this module:
- ISO_VARYING_STRING Module by Rich Townsend
- iso_varying_string implementation by Brad Richardson (@everythingfunctional)
- ISO_VARYING_STRING due to J.L.Schonfelder (author of the
iso_varying_string
proposal; the module dates back to 1998)
I also found the following Fortran libraries targeting string handling:
- Strings For Fortran by Brad Richardson @everythingfunctional
- Fortran Character String Utilities by George Benthien
- M_STRINGS from Urban Jost @urbanjost (part of General-Purpose Fortran tools)
- String_Functions by David Frank
- StringiFor by Stefano Szaghi @szaghi
- fortranString from @bceverly
- fortran-string-utility-module by @tomedunn
- fortran-string from @dongli
- strings by @jchristopherson
- fortran_libstring from @koiking213
- fortran-strings by @eengl
- flibs by @arjenmarkus contains several modules for handling strings
- functional-fortran by @milancurcic implements several functions on strings
- ZstdFortranLib by @zbeekman has some conversion to/from other intrinsic kinds,
sub
,gsub
,split
,join
, and conversion on concatenation. WIP though - LibString, F77 string library by Giulio Vistoli & Alex Pedretti
It is likely that several of the tools in the list of popular Fortran projects also contain some tools for working with strings. Given the numerous implementations it seems like this is one of the things where the absence of the standard "... led to everybody re-inventing the wheel and to an unnecessary diversity in the most fundamental classes" to borrow the quote of B. Stroustrup in a retrospective of the C++ language.
For comparison here are some links to descriptions of string handling functions in other programming languages:
- Python: String Methods, String constants, custom string formatting, template strings
- Ruby: String class & methods
- D: std.string, std.utf, std.path, std.regex, std.ascii (see related issue Proposal for ascii #11), std.encoding, std.windows.charset, std.conv
- C: C string handling on wikipedia
- C++: std::string class, <string> header, C++ string handling on Wikipedia, Boost libraries for string and text processing
- Julia: Strings, Common operations
- MATLAB: Characters and Strings
- Rust: Strings - Rust By Example, Primitive Type str, Struct std::string::String
Obviously, for now we should not aim to cover the full set of features available in other languages. Since the scope is quite big, it might be useful to break this issue into smaller issues for distinct operations (numeric converions, comparisons, finding the occurence of string in a larger string, joining and splitting, regular expressions).
My suggestion would be to start with some of the easy functions like capitalize
, count
, endswith
, startswith
, upper
, lower
, and the conversion routines from numeric types to strings and vice-versa.