libSUFR
a LIBrary of Some Useful Fortran Routines
Functions/Subroutines
sufr_text Module Reference

Procedures to manipulate text/strings. More...

Functions/Subroutines

pure character function, dimension(len(str)) lowercase (str)
 Make a string lower case. More...
 
pure character function, dimension(len(str)) uppercase (str)
 Make a string upper case. More...
 
pure character function, dimension(len(str)) uppercaseinitial (str)
 Make a string lower case with an upper-case initial. More...
 
pure character function, dimension((len(str16)+1)/2) utf16to8 (str16)
 Convert a UTF-16 string to UTF-8. More...
 
pure subroutine replace_substring (string, str_srch, str_repl)
 Search and replace occurences of a substring in a string as often as the search string is found. More...
 
subroutine remove_substring (string, substr, debug)
 Remove a substring from a string, if present. More...
 
integer function count_substring (string, substr)
 Count how many times a substring is present in a string. More...
 
subroutine replace_string_in_textfile (file_in, file_out, str_srch, str_repl, status)
 Search and replace occurences of a string in a text file. Lines up to 9999 characters only, otherwise a warning is given. More...
 
pure logical function string_contains_one_of (string, characters)
 Verify whether a string contains any of a given list of characters. More...
 
pure character function, dimension(max(number, 1)) tabs (number)
 Print multiple tab characters. More...
 
pure character function, dimension(sign(1, number) -1) int2str (number)
 Convert an integer to a character string. More...
 
pure character function, dimension(sign(1_long, floor(number, long)) -1) dbl2str (number, decim, mark)
 Convert a double-precision real to a nice character string. Difference with the F0 format descriptor: replace leading . or -. with 0. and -0. respectively (0.1 iso .1; -0.1 iso -.1). More...
 
pure character function, dimension(sign(1_long, floor(number, long)) -1) d2s (number, decim, mark)
 Convert a double-precision real to a nice character string. Short alias for dbl2str(). More...
 
pure character function, dimension(sign(1_long, floor(number, long)) -1) d2sc (number, decim)
 Convert a double-precision real to a nice character string using a comma as decimal mark. Alias for dbl2str(number, decim, ','). More...
 
pure character function, dimension(sign(1, floor(number)) -1) real2str (number, decim, mark)
 Convert a single-precision real to a nice character string. Single-precision wrapper for dbl2str. More...
 

Detailed Description

Procedures to manipulate text/strings.

Function/Subroutine Documentation

◆ count_substring()

integer function sufr_text::count_substring ( character, dimension(*), intent(in)  string,
character, dimension(*), intent(in)  substr 
)

Count how many times a substring is present in a string.

Parameters
stringString to count substrings in.
substrSubstring to count.
Return values
countNumber of times substring was found in string.

Definition at line 271 of file text.f90.

Referenced by sufr_getopt::getopt_get_command().

◆ d2s()

pure character function, dimension (sign(1_long,floor(number,long))-1) sufr_text::d2s ( real(double), intent(in)  number,
character, intent(in)  decim,
character, dimension(*), intent(in), optional  mark 
)

Convert a double-precision real to a nice character string. Short alias for dbl2str().

Parameters
numberValue to convert
decimNumber of decimals to use
markDecimal mark to separate the integer and fractional parts; single character, e.g. "," (optional; default: ".")

Definition at line 516 of file text.f90.

References dbl2str(), sufr_kinds::double, and sufr_kinds::long.

Here is the call graph for this function:

◆ d2sc()

pure character function, dimension (sign(1_long,floor(number,long))-1) sufr_text::d2sc ( real(double), intent(in)  number,
character, intent(in)  decim 
)

Convert a double-precision real to a nice character string using a comma as decimal mark. Alias for dbl2str(number, decim, ',').

Parameters
numberValue to convert
decimNumber of decimals to use

Definition at line 544 of file text.f90.

References dbl2str(), sufr_kinds::double, and sufr_kinds::long.

Here is the call graph for this function:

◆ dbl2str()

pure character function, dimension (sign(1_long,floor(number,long))-1) sufr_text::dbl2str ( real(double), intent(in)  number,
character, intent(in)  decim,
character, dimension(*), intent(in), optional  mark 
)

Convert a double-precision real to a nice character string. Difference with the F0 format descriptor: replace leading . or -. with 0. and -0. respectively (0.1 iso .1; -0.1 iso -.1).

Parameters
numberValue to convert
decimNumber of decimals to use
markDecimal mark to separate the integer and fractional parts; single character, e.g. "," (optional; default: ".")

Definition at line 452 of file text.f90.

References sufr_kinds::double, sufr_kinds::long, and replace_substring().

Referenced by d2s(), d2sc(), and real2str().

Here is the call graph for this function:

◆ int2str()

pure character function, dimension (sign(1,number)-1) sufr_text::int2str ( integer, intent(in)  number)

Convert an integer to a character string.

Parameters
numberInteger number to convert

Definition at line 433 of file text.f90.

Referenced by sufr_getopt::getopt_get_command_argument().

◆ lowercase()

pure character function, dimension(len(str)) sufr_text::lowercase ( character, dimension(*), intent(in)  str)

Make a string lower case.

Parameters
strString

Definition at line 37 of file text.f90.

◆ real2str()

pure character function, dimension (sign(1,floor(number))-1) sufr_text::real2str ( real, intent(in)  number,
character, intent(in)  decim,
character, dimension(*), intent(in), optional  mark 
)

Convert a single-precision real to a nice character string. Single-precision wrapper for dbl2str.

Parameters
numberValue to convert
decimNumber of decimals to use
markDecimal mark to separate the integer and fractional parts; single character, e.g. "," (optional; default: ".")

Definition at line 567 of file text.f90.

References dbl2str().

Here is the call graph for this function:

◆ remove_substring()

subroutine sufr_text::remove_substring ( character, dimension(*), intent(inout)  string,
character, dimension(*), intent(in)  substr,
logical, intent(in), optional  debug 
)

Remove a substring from a string, if present.

Parameters
stringString to remove the substring from. Trailing spaces are retained, call with string(1:len_trim(string)) to ignore them and speed things up.
substrSubstring to remove
debugPrint debug info (T/F, optional)

Definition at line 222 of file text.f90.

Referenced by sufr_text_html::remove_html_bold_italics(), and sufr_text_html::remove_html_links().

◆ replace_string_in_textfile()

subroutine sufr_text::replace_string_in_textfile ( character, dimension(*), intent(in)  file_in,
character, dimension(*), intent(in)  file_out,
character, dimension(*), intent(in)  str_srch,
character, dimension(*), intent(in)  str_repl,
integer, intent(out)  status 
)

Search and replace occurences of a string in a text file. Lines up to 9999 characters only, otherwise a warning is given.

Parameters
file_inName of the text file to replace in
file_outName of the text file to store the result in
str_srchSearch string
str_replReplacement string
statusExit status: 0-ok, 1/2: could not open I/O file, 11/12: character array string too small (output)

Definition at line 314 of file text.f90.

References sufr_system::error(), sufr_system::find_free_io_unit(), and replace_substring().

Here is the call graph for this function:

◆ replace_substring()

pure subroutine sufr_text::replace_substring ( character, dimension(*), intent(inout)  string,
character, dimension(*), intent(in)  str_srch,
character, dimension(*), intent(in)  str_repl 
)

Search and replace occurences of a substring in a string as often as the search string is found.

Parameters
stringOriginal string to replace in. Trailing spaces are retained, call with string(1:len_trim(string)) to ignore them and speed things up.
str_srchSearch string
str_replReplacement string
Note
If the search string is part of the replace string, replacement is done in two steps:
  • replace the search string with a random string of the same length
  • replace the random string with the replacement string
  • this should avoid undesired outcomes for the case where the replacement string contains the search string, e.g. when replacing '.csv' with '_backup.csv', which will end up as e.g. '_backup_backup_back'

Definition at line 144 of file text.f90.

Referenced by dbl2str(), sufr_text_html::remove_html_br_p_hr(), and replace_string_in_textfile().

◆ string_contains_one_of()

pure logical function sufr_text::string_contains_one_of ( character, dimension(*), intent(in)  string,
character, dimension(*), intent(in)  characters 
)

Verify whether a string contains any of a given list of characters.

Parameters
stringString to verify
charactersList of characters
Return values
string_contains_one_ofTrue if the string contains one of the specified characters, otherwise false

Definition at line 384 of file text.f90.

◆ tabs()

pure character function, dimension(max(number,1)) sufr_text::tabs ( integer, intent(in)  number)

Print multiple tab characters.

Parameters
numberDesired number of tab characters

Definition at line 410 of file text.f90.

◆ uppercase()

pure character function, dimension(len(str)) sufr_text::uppercase ( character, dimension(*), intent(in)  str)

Make a string upper case.

Parameters
strString

Definition at line 60 of file text.f90.

◆ uppercaseinitial()

pure character function, dimension(len(str)) sufr_text::uppercaseinitial ( character, dimension(*), intent(in)  str)

Make a string lower case with an upper-case initial.

Parameters
strString

Definition at line 83 of file text.f90.

◆ utf16to8()

pure character function, dimension((len(str16)+1)/2) sufr_text::utf16to8 ( character, dimension(*), intent(in)  str16)

Convert a UTF-16 string to UTF-8.

Parameters
str16UTF-16 string
Return values
UTF16to8UTF-8 string (about half the length of str16)

Definition at line 112 of file text.f90.

References sufr_system::warn().

Here is the call graph for this function: