OOP designed string class.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(kind=CK, len=:), | public, | allocatable | :: | raw |
Raw data. |
Adjustl replacement.
Left adjust a string by removing leading spaces.
type(string) :: astring
astring = ' Hello World!'
print "(L1)", astring%adjustl()//''=='Hello World! '
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Adjusted string.
Adjustr replacement.
Right adjust a string by removing leading spaces.
type(string) :: astring
astring = 'Hello World! '
print "(L1)", astring%adjustr()//''==' Hello World!'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Adjusted string.
Count replacement.
Count the number of occurences of a substring into a string.
If ignore_isolated
is set to true the eventual “isolated” occurences are ignored: an isolated occurrences are those
occurrences happening at the start of string (thus not having a left companion) or at the end of the string (thus not having a
right companion).
type(string) :: astring
logical :: test_passed(4)
astring = ' Hello World ! '
test_passed(1) = astring%count(substring=' ')==10
astring = 'Hello World ! '
test_passed(2) = astring%count(substring=' ', ignore_isolated=.true.)==6
astring = ' Hello World !'
test_passed(3) = astring%count(substring=' ', ignore_isolated=.true.)==6
astring = ' Hello World ! '
test_passed(4) = astring%count(substring=' ', ignore_isolated=.true.)==8
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | substring |
Substring. |
||
logical, | intent(in), | optional | :: | ignore_isolated |
Ignore “isolated” occurrences. |
Number of occurrences.
Index replacement.
Return the position of the start of the first occurrence of string substring
as a substring in string
, counting from one.
If substring
is not present in string
, zero is returned. If the back argument is present and true, the return value is
the start of the last occurrence rather than the first.
type(string) :: string1
type(string) :: string2
logical :: test_passed(2)
string1 = 'Hello World Hello!'
string2 = 'llo'
test_passed(1) = string1%index(substring=string2)==index(string='Hello World Hello!', substring='llo')
test_passed(2) = string1%index(substring=string2, back=.true.)==index(string='Hello World Hello!', substring='llo', &
back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | substring |
Searched substring. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Return the position of the start of the first occurrence of string substring
as a substring in string
, counting from one.
If substring
is not present in string
, zero is returned. If the back argument is present and true, the return value is
the start of the last occurrence rather than the first.
type(string) :: string1
logical :: test_passed(2)
string1 = 'Hello World Hello!'
test_passed(1) = string1%index(substring='llo')==index(string='Hello World Hello!', substring='llo')
test_passed(2) = string1%index(substring='llo', back=.true.)==index(string='Hello World Hello!', substring='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | substring |
Searched substring. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Len replacement.
Return the length of a string.
type(string) :: astring
astring = 'Hello World! '
print "(L1)", astring%len()==len('Hello World! ')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
String length.
Len_trim replacement.
Return the length of a string, ignoring any trailing blanks.
type(string) :: astring
astring = 'Hello World! '
print "(L1)", astring%len_trim()==len_trim('Hello World! ')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
String length.
Repeat replacement.
Concatenates several copies of an input string.
type(string) :: astring
astring = 'x'
print "(L1)", astring%repeat(5)//''=='xxxxx'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
String to be repeated. |
||
integer, | intent(in) | :: | ncopies |
Number of string copies. |
Repeated string.
Concatenates several copies of an input string.
type(string) :: astring
astring = 'y'
print "(L1)", astring%repeat('x', 5)//''=='xxxxx'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | rstring |
String to be repeated. |
||
integer, | intent(in) | :: | ncopies |
Number of string copies. |
Repeated string.
Scan replacement.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is in set
.
type(string) :: string1
type(string) :: string2
logical :: test_passed(2)
string1 = 'Hello World Hello!'
string2 = 'llo'
test_passed(1) = string1%scan(set=string2)==scan(string='Hello World Hello!', set='llo')
test_passed(2) = string1%scan(set=string2, back=.true.)==scan(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is in set
.
type(string) :: string1
logical :: test_passed(2)
string1 = 'Hello World Hello!'
test_passed(1) = string1%scan(set='llo')==scan(string='Hello World Hello!', set='llo')
test_passed(2) = string1%scan(set='llo', back=.true.)==scan(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Trim replacement.
Remove trailing spaces.
type(string) :: astring
astring = 'Hello World! '
print "(L1)", astring%trim()==trim('Hello World! ')
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Trimmed string.
Verify replacement.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is not
in set
. If all characters of string
are found in set
, the result is zero.
type(string) :: string1
type(string) :: string2
logical :: test_passed(2)
string1 = 'Hello World Hello!'
string2 = 'llo'
test_passed(1) = string1%verify(set=string2)==verify(string='Hello World Hello!', set='llo')
test_passed(2) = string1%verify(set=string2, back=.true.)==verify(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is not
in set
. If all characters of string
are found in set
, the result is zero.
type(string) :: string1
logical :: test_passed(2)
string1 = 'Hello World Hello!'
test_passed(1) = string1%verify(set='llo')==verify(string='Hello World Hello!', set='llo')
test_passed(2) = string1%verify(set='llo', back=.true.)==verify(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Return the base directory name of a string containing a file name.
Return the base directory name of a string containing a file name.
type(string) :: string1
logical :: test_passed(4)
string1 = '/bar/foo.tar.bz2'
test_passed(1) = string1%basedir()//''=='/bar'
string1 = './bar/foo.tar.bz2'
test_passed(2) = string1%basedir()//''=='./bar'
string1 = 'bar/foo.tar.bz2'
test_passed(3) = string1%basedir()//''=='bar'
string1 = '\bar\foo.tar.bz2'
test_passed(4) = string1%basedir(sep='\')//''=='\bar'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Directory separator. |
Base directory name.
Return the base file name of a string containing a file name.
Return the base file name of a string containing a file name.
Optionally, the extension is also stripped if provided or the last one if required, e.g.
type(string) :: astring
logical :: test_passed(5)
astring = 'bar/foo.tar.bz2'
test_passed(1) = astring%basename()//''=='foo.tar.bz2'
test_passed(2) = astring%basename(extension='.tar.bz2')//''=='foo'
test_passed(3) = astring%basename(strip_last_extension=.true.)//''=='foo.tar'
astring = '\bar\foo.tar.bz2'
test_passed(4) = astring%basename(sep='\')//''=='foo.tar.bz2'
astring = 'bar'
test_passed(5) = astring%basename(strip_last_extension=.true.)//''=='bar'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Directory separator. |
|
character(kind=CK, len=*), | intent(in), | optional | :: | extension |
File extension. |
|
logical, | intent(in), | optional | :: | strip_last_extension |
Flag to enable the stripping of last extension. |
Base file name.
Return a string with all words capitalized without spaces.
Return a string with all words capitalized without spaces.
Multiple subsequent separators are collapsed to one occurence.
type(string) :: astring
astring = 'caMeL caSe var'
print '(L1)', astring%camelcase()//''=='CamelCaseVar'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
Camel case string.
Return a string with its first character capitalized and the rest lowercased.
Return a string with its first character capitalized and the rest lowercased.
type(string) :: astring
astring = 'say all Hello WorLD!'
print '(L1)', astring%capitalize()//''=='Say all hello world!'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Upper case string.
Return the raw characters data.
Return the raw characters data.
type(string) :: astring
astring = 'say all Hello WorLD!'
print '(L1)', astring%chars()=='say all Hello WorLD!'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Raw characters data.
Colorize and stylize strings.
Colorize and stylize strings, DEFAULT kind.
type(string) :: astring
astring = 'say all Hello WorLD!'
print '(L1)', astring%colorize(color_fg='red')=='[31msay all Hello WorLD![0m'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in), | optional | :: | color_fg |
Foreground color definition. |
|
character(len=*), | intent(in), | optional | :: | color_bg |
Background color definition. |
|
character(len=*), | intent(in), | optional | :: | style |
Style definition. |
Colorized string.
Decode string.
Return a string decoded accordingly the codec.
Only BASE64 codec is currently available.
type(string) :: astring
astring = 'SG93IGFyZSB5b3U/'
print '(L1)', astring%decode(codec='base64')//''=='How are you?'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | codec |
Encoding codec. |
Decoded string.
Encode string.
Return a string encoded accordingly the codec.
Only BASE64 codec is currently available.
type(string) :: astring
astring = 'How are you?'
print '(L1)', astring%encode(codec='base64')//''=='SG93IGFyZSB5b3U/'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | codec |
Encoding codec. |
Encoded string.
Escape backslashes (or custom escape character).
Escape backslashes (or custom escape character).
type(string) :: astring
logical :: test_passed(2)
astring = '^\s \d+\s*'
test_passed(1) = astring%escape(to_escape='\')//''=='^\\s \\d+\\s*'
test_passed(2) = astring%escape(to_escape='\', esc='|')//''=='^|\s |\d+|\s*'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=1), | intent(in) | :: | to_escape |
Character to be escaped. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | esc |
Character used to escape. |
Escaped string.
Return the extension of a string containing a file name.
Return the extension of a string containing a file name.
type(string) :: astring
astring = '/bar/foo.tar.bz2'
print '(L1)', astring%extension()//''=='.bz2'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Extension file name.
Pad string on the left (or right) with zeros (or other char) to fill width.
Pad string on the left (or right) with zeros (or other char) to fill width.
type(string) :: astring
logical :: test_passed(4)
astring = 'this is string example....wow!!!'
test_passed(1) = astring%fill(width=40)//''=='00000000this is string example....wow!!!'
test_passed(2) = astring%fill(width=50)//''=='000000000000000000this is string example....wow!!!'
test_passed(3) = astring%fill(width=50, right=.true.)//''=='this is string example....wow!!!000000000000000000'
test_passed(4) = astring%fill(width=40, filling_char='*')//''=='********this is string example....wow!!!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer, | intent(in) | :: | width |
Final width of filled string. |
||
logical, | intent(in), | optional | :: | right |
Fill on the right instead of left. |
|
character(kind=CK, len=1), | intent(in), | optional | :: | filling_char |
Filling character (default “0”). |
Filled string.
Free dynamic memory.
Glob search, finds all the pathnames matching a given pattern.
Glob search (character output), finds all the pathnames matching a given pattern according to the rules used by the Unix shell.
Method not portable: works only on Unix/GNU Linux OS.
type(string) :: astring
character(len=:), allocatable :: alist_chr(:)
integer, parameter :: Nf=5
character(14) :: files(1:Nf)
integer :: file_unit
integer :: f
integer :: ff
logical :: test_passed
do f=1, Nf
files(f) = astring%tempname(prefix='foo-')
open(newunit=file_unit, file=files(f))
write(file_unit, *)f
close(unit=file_unit)
enddo
call astring%glob(pattern='foo-*', list=alist_chr)
do f=1, Nf
open(newunit=file_unit, file=files(f))
close(unit=file_unit, status='delete')
enddo
test_passed = .false.
outer_chr: do f=1, size(alist_chr, dim=1)
do ff=1, Nf
test_passed = alist_chr(f) == files(ff)
if (test_passed) cycle outer_chr
enddo
enddo outer_chr
print '(L1)', test_passed
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | pattern |
Given pattern. |
||
character(len=:), | intent(out), | allocatable | :: | list(:) |
List of matching pathnames. |
Glob search (string output), finds all the pathnames matching a given pattern according to the rules used by the Unix shell.
Method not portable: works only on Unix/GNU Linux OS.
type(string) :: astring
type(string), allocatable :: alist_str(:)
integer, parameter :: Nf=5
character(14) :: files(1:Nf)
integer :: file_unit
integer :: f
integer :: ff
logical :: test_passed
do f=1, Nf
files(f) = astring%tempname(prefix='foo-')
open(newunit=file_unit, file=files(f))
write(file_unit, *)f
close(unit=file_unit)
enddo
call astring%glob(pattern='foo-*', list=alist_str)
do f=1, Nf
open(newunit=file_unit, file=files(f))
close(unit=file_unit, status='delete')
enddo
test_passed = .false.
outer_str: do f=1, size(alist_str, dim=1)
do ff=1, Nf
test_passed = alist_str(f) == files(ff)
if (test_passed) cycle outer_str
enddo
enddo outer_str
print '(L1)', test_passed
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | pattern |
Given pattern. |
||
type(string), | intent(out), | allocatable | :: | list(:) |
List of matching pathnames. |
Insert substring into string at a specified position.
Insert substring into string at a specified position.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(5)
astring = 'this is string example wow!!!'
anotherstring = '... '
test_passed(1) = astring%insert(substring=anotherstring, pos=1)//''=='... this is string example wow!!!'
test_passed(2) = astring%insert(substring=anotherstring, pos=23)//''=='this is string example... wow!!!'
test_passed(3) = astring%insert(substring=anotherstring, pos=29)//''=='this is string example wow!!!... '
test_passed(4) = astring%insert(substring=anotherstring, pos=-1)//''=='... this is string example wow!!!'
test_passed(5) = astring%insert(substring=anotherstring, pos=100)//''=='this is string example wow!!!... '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | substring |
Substring. |
||
integer, | intent(in) | :: | pos |
Position from which insert substring. |
Inserted string.
Insert substring into string at a specified position.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(5)
astring = 'this is string example wow!!!'
acharacter = '... '
test_passed(1) = astring%insert(substring=acharacter, pos=1)//''=='... this is string example wow!!!'
test_passed(2) = astring%insert(substring=acharacter, pos=23)//''=='this is string example... wow!!!'
test_passed(3) = astring%insert(substring=acharacter, pos=29)//''=='this is string example wow!!!... '
test_passed(4) = astring%insert(substring=acharacter, pos=-1)//''=='... this is string example wow!!!'
test_passed(5) = astring%insert(substring=acharacter, pos=100)//''=='this is string example wow!!!... '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | substring |
Substring. |
||
integer, | intent(in) | :: | pos |
Position from which insert substring. |
Inserted string.
Return a string that is a join of an array of strings or characters.
Return a string that is a join of an array of strings.
The join-separator is set equals to self if self has a value or it is set to a null string ‘’. This value can be overridden passing a custom separator.
type(string) :: astring
type(string) :: strings(3)
logical :: test_passed(5)
strings(1) = 'one'
strings(2) = 'two'
strings(3) = 'three'
test_passed(1) = (astring%join(array=strings)//''==strings(1)//strings(2)//strings(3))
test_passed(2) = (astring%join(array=strings, sep='-')//''==strings(1)//'-'//strings(2)//'-'//strings(3))
call strings(1)%free
strings(2) = 'two'
strings(3) = 'three'
test_passed(3) = (astring%join(array=strings, sep='-')//''==strings(2)//'-'//strings(3))
strings(1) = 'one'
strings(2) = 'two'
call strings(3)%free
test_passed(4) = (astring%join(array=strings, sep='-')//''==strings(1)//'-'//strings(2))
strings(1) = 'one'
call strings(2)%free
strings(3) = 'three'
test_passed(5) = (astring%join(array=strings, sep='-')//''==strings(1)//'-'//strings(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
The join of array.
Return a string that is a join of an array of characters.
The join-separator is set equals to self if self has a value or it is set to a null string ‘’. This value can be overridden passing a custom separator.
type(string) :: astring
character(5) :: characters(3)
logical :: test_passed(6)
characters(1) = 'one'
characters(2) = 'two'
characters(3) = 'three'
test_passed(1) = (astring%join(array=characters)//''==characters(1)//characters(2)//characters(3))
test_passed(2) = (astring%join(array=characters, sep='-')//''==characters(1)//'-'//characters(2)//'-'//characters(3))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(3) = (astring%join(array=characters, sep='-')//''==characters(2)//'-'//characters(3))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(4) = (astring%join(array=characters, sep='-')//''==characters(1)//'-'//characters(2))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(5) = (astring%join(array=characters, sep='-')//''==characters(1)//'-'//characters(3))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = 'three'
astring = '_'
test_passed(6) = (astring%join(array=characters)//''==characters(1)//'_'//characters(2)//'_'//characters(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
The join of array.
Return a string that is a join of an array of strings or characters; Return join 1D string array of an 2D array of strings or characters in columns or rows.
Return a string that is a join of an array of strings.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified.
type(string) :: strings(3)
logical :: test_passed(5)
strings(1) = 'one'
strings(2) = 'two'
strings(3) = 'three'
test_passed(1) = (strjoin(array=strings)//''==strings(1)//strings(2)//strings(3))
test_passed(2) = (strjoin(array=strings, sep='-')//''==strings(1)//'-'//strings(2)//'-'//strings(3))
call strings(1)%free
strings(2) = 'two'
strings(3) = 'three'
test_passed(3) = (strjoin(array=strings, sep='-')//''==strings(2)//'-'//strings(3))
strings(1) = 'one'
strings(2) = 'two'
call strings(3)%free
test_passed(4) = (strjoin(array=strings, sep='-')//''==strings(1)//'-'//strings(2))
strings(1) = 'one'
call strings(2)%free
strings(3) = 'three'
test_passed(5) = (strjoin(array=strings, sep='-')//''==strings(1)//'-'//strings(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
The join of array.
Return a string that is a join of an array of characters.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified. The trim function is applied to array items if optional logical is_trim variable isn’t set to .false.
character(5) :: characters(3)
logical :: test_passed(13)
characters(1) = 'one'
characters(2) = 'two'
characters(3) = 'three'
test_passed(1) = (strjoin(array=characters)//''==trim(characters(1))//trim(characters(2))//trim(characters(3)))
test_passed(2) = (strjoin(array=characters, sep='-')//''==trim(characters(1))//'-'//trim(characters(2))//'-'//trim(characters(3)))
test_passed(3) = ( strjoin(array=characters, is_trim=.false.)//''==characters(1)//characters(2)//characters(3))
test_passed(4) = ( strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(1)//'-'//characters(2)//'-'//characters(3))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(5) = (strjoin(array=characters)//''==trim(characters(2))//trim(characters(3)))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(6) = (strjoin(array=characters)//''==trim(characters(1))//trim(characters(2)))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(7) = (strjoin(array=characters)//''==trim(characters(1))//trim(characters(3)))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(8) = (strjoin(array=characters, sep='-')//''==trim(characters(2))//'-'//trim(characters(3)))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(9) = (strjoin(array=characters, sep='-')//''==trim(characters(1))//'-'//trim(characters(2)))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(10) = (strjoin(array=characters, sep='-')//''==trim(characters(1))//'-'//trim(characters(3)))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(11) = (strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(2)//'-'//characters(3))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(12) = (strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(1)//'-'//characters(2))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(13) = (strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(1)//'-'//characters(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
|
logical, | intent(in), | optional | :: | is_trim |
Flag to setup trim character or not |
The join of array.
Return a string that is a join of columns or rows of an array of strings.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified. The is_col is setup the direction of join: within default columns (.true.) or rows(.false.).
type(string), allocatable :: strings_arr(:, :)
logical :: test_passed(5)
strings_arr = reshape( source = &
[string('one'), string('two'), string('three'), &
string('ONE'), string('TWO'), string('THREE')], &
shape = [3, 2] )
test_passed(1) = all( strjoin(array=strings_arr) == &
reshape([string('onetwothree'), string('ONETWOTHREE')], &
shape = [2]) )
test_passed(2) = all( strjoin(array=strings_arr, sep='_') == &
reshape([string('one_two_three'), string('ONE_TWO_THREE')], &
shape = [2]) )
test_passed(3) = all( strjoin(array=strings_arr, is_col=.false.) == &
reshape([string('oneONE'), string('twoTWO'), string('threeTHREE')], &
shape = [3]) )
test_passed(4) = all( strjoin(array=strings_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), string('two_TWO'), string('three_THREE')], &
shape = [3]) )
call strings_arr(2, 1)%free
test_passed(5) = all( strjoin(array=strings_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), string('TWO'), string('three_THREE')], &
shape = [3]) )
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | array(1:,1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
|
logical, | intent(in), | optional | :: | is_col |
Direction: ‘columns’ if .true. or ‘rows’ if .false. |
The join of array.
Return a string that is a join of columns or rows of an array of characters.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified. The trim function is applied to array items if optional logical is_trim variable isn’t set to .false. The is_col is setup the direction of join: within default columns (.true.) or rows(.false.).
character(len=10) :: chars_arr(3, 2)
logical :: test_passed(9)
chars_arr(:, 1) = ['one ', 'two ', 'three ']
chars_arr(:, 2) = ['ONE ', 'TWO ', 'THREE ']
test_passed(1) = all( strjoin(array=chars_arr) == &
reshape([string('onetwothree'), string('ONETWOTHREE')], &
shape = [2]) )
test_passed(2) = all( strjoin(array=chars_arr, is_trim=.false.) == &
reshape([string('one two three '), &
string('ONE TWO THREE ')], &
shape = [2]) )
test_passed(3) = all( strjoin(array=chars_arr, sep='_') == &
reshape([string('one_two_three'), string('ONE_TWO_THREE')], &
shape = [2]) )
test_passed(4) = all( strjoin(array=chars_arr, sep='_', is_trim=.false.) == &
reshape([string('one _two _three '), &
string('ONE _TWO _THREE ')], &
shape = [2]) )
test_passed(5) = all( strjoin(array=chars_arr, is_col=.false.) == &
reshape([string('oneONE'), string('twoTWO'), string('threeTHREE')], &
shape = [3]) )
test_passed(6) = all( strjoin(array=chars_arr, is_trim=.false., is_col=.false.) == &
reshape([string('one ONE '), &
string('two TWO '), &
string('three THREE ')], &
shape = [3]) )
test_passed(7) = all( strjoin(array=chars_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), string('two_TWO'), string('three_THREE')], &
shape = [3]) )
test_passed(8) = all( strjoin(array=chars_arr, sep='_', is_trim=.false., is_col=.false.) == &
reshape([string('one _ONE '), &
string('two _TWO '), &
string('three _THREE ')], &
shape = [3]) )
chars_arr(2,1) = ''
test_passed(9) = all( strjoin(array=chars_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), &
string('TWO'), &
string('three_THREE')], &
shape = [3]) )
print '(L1)', all(test_passed)
all items of character array have equal lengths
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | array(1:,1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
|
logical, | intent(in), | optional | :: | is_trim |
Flag to setup trim character or not |
|
logical, | intent(in), | optional | :: | is_col |
Direction: ‘columns’ if .true. or ‘rows’ if .false. |
The join of array.
Return a string with all lowercase characters.
Return a string with all lowercase characters.
type(string) :: astring
logical :: test_passed(1)
astring = 'Hello WorLD!'
test_passed(1) = astring%lower()//''=='hello world!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Upper case string.
Split string at separator and return the 3 parts (before, the separator and after).
Split string at separator and return the 3 parts (before, the separator and after).
type(string) :: astring
type(string) :: strings(3)
logical :: test_passed(3)
astring = 'Hello WorLD!'
strings = astring%partition(sep='lo Wo')
test_passed(1) = (strings(1)//''=='Hel'.and.strings(2)//''=='lo Wo'.and.strings(3)//''=='rLD!')
strings = astring%partition(sep='Hello')
test_passed(2) = (strings(1)//''==''.and.strings(2)//''=='Hello'.and.strings(3)//''==' WorLD!')
astring = 'Hello WorLD!'
strings = astring%partition()
test_passed(3) = (strings(1)//''=='Hello'.and.strings(2)//''==' '.and.strings(3)//''=='WorLD!')
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
after the separator.
Read a file a single string stream.
Read a file as a single string stream.
All the lines are stored into the string self as a single ascii stream. Each line (record) is separated by a new_line
character.
For unformatted read only access='stream'
is supported with new_line as line terminator.
Fast file reading allows a very efficient reading of streamed file, but it dumps file as single streamed string.
type(string) :: astring
type(string), allocatable :: strings(:)
type(string) :: line(3)
integer :: iostat
character(len=99) :: iomsg
integer :: scratch
integer :: l
logical :: test_passed(9)
line(1) = ' Hello World! '
line(2) = 'How are you? '
line(3) = ' All say: "Fine thanks"'
open(newunit=scratch, file='read_file_test.tmp')
write(scratch, "(A)") line(1)%chars()
write(scratch, "(A)") line(2)%chars()
write(scratch, "(A)") line(3)%chars()
close(scratch)
call astring%read_file(file='read_file_test.tmp', iostat=iostat, iomsg=iomsg)
call astring%split(tokens=strings, sep=new_line('a'))
test_passed(1) = (size(strings, dim=1)==size(line, dim=1))
do l=1, size(strings, dim=1)
test_passed(l+1) = (strings(l)==line(l))
enddo
open(newunit=scratch, file='read_file_test.tmp', form='UNFORMATTED', access='STREAM')
write(scratch) line(1)%chars()//new_line('a')
write(scratch) line(2)%chars()//new_line('a')
write(scratch) line(3)%chars()//new_line('a')
close(scratch)
call astring%read_file(file='read_file_test.tmp', form='unformatted', iostat=iostat, iomsg=iomsg)
call astring%split(tokens=strings, sep=new_line('a'))
test_passed(5) = (size(strings, dim=1)==size(line, dim=1))
do l=1, size(strings, dim=1)
test_passed(l+5) = (strings(l)==line(l))
enddo
open(newunit=scratch, file='read_file_test.tmp', form='UNFORMATTED', access='STREAM')
close(scratch, status='DELETE')
call astring%read_file(file='read_file_test.tmp', iostat=iostat)
test_passed(9) = (iostat/=0)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | file |
File name. |
||
logical, | intent(in), | optional | :: | is_fast |
Flag to enable (super) fast file reading. |
|
character(len=*), | intent(in), | optional | :: | form |
Format of unit. |
|
integer, | intent(out), | optional | :: | iostat |
IO status code. |
|
character(len=*), | intent(inout), | optional | :: | iomsg |
IO status message. |
Read line (record) from a connected unit.
Read line (record) from a connected unit.
The line is read as an ascii stream read until the eor is reached.
For unformatted read only access='stream'
is supported with new_line as line terminator.
type(string) :: astring
type(string) :: line(3)
integer :: iostat
character(len=99) :: iomsg
integer :: scratch
integer :: l
logical :: test_passed(6)
line(1) = ' Hello World! '
line(2) = 'How are you? '
line(3) = ' All say: "Fine thanks"'
open(newunit=scratch, status='SCRATCH')
write(scratch, "(A)") line(1)%chars()
write(scratch, "(A)") line(2)%chars()
write(scratch, "(A)") line(3)%chars()
rewind(scratch)
l = 0
iostat = 0
do
l = l + 1
call astring%read_line(unit=scratch, iostat=iostat, iomsg=iomsg)
if (iostat/=0.and..not.is_iostat_eor(iostat)) then
exit
else
test_passed(l) = (astring==line(l))
endif
enddo
close(scratch)
open(newunit=scratch, status='SCRATCH', form='UNFORMATTED', access='STREAM')
write(scratch) line(1)%chars()//new_line('a')
write(scratch) line(2)%chars()//new_line('a')
write(scratch) line(3)%chars()//new_line('a')
rewind(scratch)
l = 0
iostat = 0
do
l = l + 1
call astring%read_line(unit=scratch, iostat=iostat, iomsg=iomsg, form='UnfORMatteD')
if (iostat/=0.and..not.is_iostat_eor(iostat)) then
exit
else
test_passed(l+3) = (astring==line(l))
endif
enddo
close(scratch)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | self |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(len=*), | intent(in), | optional | :: | form |
Format of unit. |
|
integer, | intent(out), | optional | :: | iostat |
IO status code. |
|
character(len=*), | intent(inout), | optional | :: | iomsg |
IO status message. |
Read (all) lines (records) from a connected unit as a single ascii stream.
Read (all) lines (records) from a connected unit as a single ascii stream.
All the lines are stored into the string self as a single ascii stream. Each line (record) is separated by a new_line
character. The line is read as an ascii stream read until the eor is reached.
The connected unit is rewinded. At a successful exit current record is at eof, at the beginning otherwise.
For unformatted read only access='stream'
is supported with new_line as line terminator.
type(string) :: astring
type(string), allocatable :: strings(:)
type(string) :: line(3)
integer :: iostat
character(len=99) :: iomsg
integer :: scratch
integer :: l
logical :: test_passed(8)
line(1) = ' Hello World! '
line(2) = 'How are you? '
line(3) = ' All say: "Fine thanks"'
open(newunit=scratch, status='SCRATCH')
write(scratch, "(A)") line(1)%chars()
write(scratch, "(A)") line(2)%chars()
write(scratch, "(A)") line(3)%chars()
call astring%read_lines(unit=scratch, iostat=iostat, iomsg=iomsg)
call astring%split(tokens=strings, sep=new_line('a'))
test_passed(1) = (size(strings, dim=1)==size(line, dim=1))
do l=1, size(strings, dim=1)
test_passed(l+1) = (strings(l)==line(l))
enddo
close(scratch)
open(newunit=scratch, status='SCRATCH', form='UNFORMATTED', access='STREAM')
write(scratch) line(1)%chars()//new_line('a')
write(scratch) line(2)%chars()//new_line('a')
write(scratch) line(3)%chars()//new_line('a')
call astring%read_lines(unit=scratch, form='unformatted', iostat=iostat, iomsg=iomsg)
call astring%split(tokens=strings, sep=new_line('a'))
test_passed(5) = (size(strings, dim=1)==size(line, dim=1))
do l=1, size(strings, dim=1)
test_passed(l+5) = (strings(l)==line(l))
enddo
close(scratch)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | self |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(len=*), | intent(in), | optional | :: | form |
Format of unit. |
|
integer, | intent(out), | optional | :: | iostat |
IO status code. |
|
character(len=*), | intent(inout), | optional | :: | iomsg |
IO status message. |
Return a string with all occurrences of substring old replaced by new.
Return a string with all occurrences of substring old replaced by new.
type(string) :: astring
logical :: test_passed(3)
astring = 'When YOU are sad YOU should think to me :-)'
test_passed(1) = (astring%replace(old='YOU', new='THEY')//''=='When THEY are sad THEY should think to me :-)')
test_passed(2) = (astring%replace(old='YOU', new='THEY', count=1)//''=='When THEY are sad YOU should think to me :-)')
astring = repeat(new_line('a')//'abcd', 20)
astring = astring%replace(old=new_line('a'), new='|cr|')
astring = astring%replace(old='|cr|', new=new_line('a')//' ')
test_passed(3) = (astring//''==repeat(new_line('a')//' '//'abcd', 20))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | old |
Old substring. |
||
character(kind=CK, len=*), | intent(in) | :: | new |
New substring. |
||
integer, | intent(in), | optional | :: | count |
Number of old occurences to be replaced. |
The string with old replaced by new.
Return a reversed string.
Return a reversed string.
type(string) :: astring
logical :: test_passed(2)
astring = 'abcdefghilmnopqrstuvz'
test_passed(1) = (astring%reverse()//''=='zvutsrqponmlihgfedcba')
astring = '0123456789'
test_passed(2) = (astring%reverse()//''=='9876543210')
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
The reversed string.
Search for tagged record into string.
Search for tagged record into string, return the first record found (if any) matching the tags.
Optionally, returns the indexes of tag start/end, thus this is not an elemental
function.
The tagged record is searched into self if allocated otherwise into in_string
if passed or, eventually, into
in_character
is passed. If tag is not found the return string is not allocated and the start/end indexes (if requested) are
zero.
type(string) :: astring
type(string) :: anotherstring
character(len=:), allocatable :: acharacter
integer :: istart
integer :: iend
logical :: test_passed(5)
astring = '<test> <first> hello </first> <first> not the first </first> </test>'
anotherstring = astring%search(tag_start='<first>', tag_end='</first>')
test_passed(1) = anotherstring//''=='<first> hello </first>'
astring = '<test> <a> <a> <a> the nested a </a> </a> </a> </test>'
anotherstring = astring%search(tag_start='<a>', tag_end='</a>')
test_passed(2) = anotherstring//''=='<a> <a> <a> the nested a </a> </a> </a>'
call astring%free
anotherstring = '<test> <a> <a> <a> the nested a </a> </a> </a> </test>'
astring = astring%search(in_string=anotherstring, tag_start='<a>', tag_end='</a>')
test_passed(3) = astring//''=='<a> <a> <a> the nested a </a> </a> </a>'
call astring%free
acharacter = '<test> <a> <a> <a> the nested a </a> </a> </a> </test>'
astring = astring%search(in_character=acharacter, tag_start='<a>', tag_end='</a>')
test_passed(4) = astring//''=='<a> <a> <a> the nested a </a> </a> </a>'
acharacter = '<test> <first> hello </first> <sec> <sec>not the first</sec> </sec> </test>'
astring = astring%search(in_character=acharacter, tag_start='<sec>', tag_end='</sec>', istart=istart, iend=iend)
test_passed(5) = astring//''==acharacter(31:67)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | tag_start |
Start tag. |
||
character(kind=CK, len=*), | intent(in) | :: | tag_end |
End tag. |
||
type(string), | intent(in), | optional | :: | in_string |
Search into this string. |
|
character(kind=CK, len=*), | intent(in), | optional | :: | in_character |
Search into this character string. |
|
integer, | intent(out), | optional | :: | istart |
Starting index of tag inside the string. |
|
integer, | intent(out), | optional | :: | iend |
Ending index of tag inside the string. |
First tag found.
Return the raw characters data sliced.
Return the raw characters data sliced.
type(string) :: astring
astring = 'the Quick Brown fox Jumps over the Lazy Dog.'
print "(A)", astring%slice(11,25)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer, | intent(in) | :: | istart |
Slice start index. |
||
integer, | intent(in) | :: | iend |
Slice end index. |
Raw characters data.
Return a string with all words lowercase separated by “_”.
Return a string with all words lowercase separated by “_”.
Multiple subsequent separators are collapsed to one occurence.
type(string) :: astring
logical :: test_passed(1)
astring = 'the Quick Brown fox Jumps over the Lazy Dog.'
test_passed(1) = astring%snakecase()//''=='the_quick_brown_fox_jumps_over_the_lazy_dog.'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
Snake case string.
Return a list of substring in the string, using sep as the delimiter string.
Return a list of substring in the string, using sep as the delimiter string.
Multiple subsequent separators are collapsed to one occurrence.
If max_tokens
is passed the returned number of tokens is either max_tokens
or max_tokens + 1
.
type(string) :: astring
type(string), allocatable :: strings(:)
logical :: test_passed(11)
astring = '+ab-++cre-++cre-ab+'
call astring%split(tokens=strings, sep='+')
test_passed(1) = (strings(1)//''=='ab-'.and.strings(2)//''=='cre-'.and.strings(3)//''=='cre-ab')
astring = 'ab-++cre-++cre-ab+'
call astring%split(tokens=strings, sep='+')
test_passed(2) = (strings(1)//''=='ab-'.and.strings(2)//''=='cre-'.and.strings(3)//''=='cre-ab')
astring = 'ab-++cre-++cre-ab'
call astring%split(tokens=strings, sep='+')
test_passed(3) = (strings(1)//''=='ab-'.and.strings(2)//''=='cre-'.and.strings(3)//''=='cre-ab')
astring = 'Hello '//new_line('a')//'World!'
call astring%split(tokens=strings, sep=new_line('a'))
test_passed(4) = (strings(1)//''=='Hello '.and.strings(2)//''=='World!')
astring = 'Hello World!'
call astring%split(tokens=strings)
test_passed(5) = (strings(1)//''=='Hello'.and.strings(2)//''=='World!')
astring = '+ab-'
call astring%split(tokens=strings, sep='+')
test_passed(6) = (strings(1)//''=='ab-')
astring = '+ab-'
call astring%split(tokens=strings, sep='-')
test_passed(7) = (strings(1)//''=='+ab')
astring = '+ab-+cd-'
call astring%split(tokens=strings, sep='+')
test_passed(8) = (strings(1)//''=='ab-'.and.strings(2)//''=='cd-')
astring = 'ab-+cd-+'
call astring%split(tokens=strings, sep='+')
test_passed(9) = (strings(1)//''=='ab-'.and.strings(2)//''=='cd-')
astring = '+ab-+cd-+'
call astring%split(tokens=strings, sep='+')
test_passed(10) = (strings(1)//''=='ab-'.and.strings(2)//''=='cd-')
astring = '1-2-3-4-5-6-7-8'
call astring%split(tokens=strings, sep='-', max_tokens=3)
test_passed(11) = (strings(1)//''=='1'.and.strings(2)//''=='2'.and.strings(3)//''=='3'.and.strings(4)//''=='4-5-6-7-8')
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(out), | allocatable | :: | tokens(:) |
Tokens substring. |
|
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
|
integer, | intent(in), | optional | :: | max_tokens |
Fix the maximum number of returned tokens. |
Return a list of substring in the string, using sep as the delimiter string.
Return a list of substring in the string, using sep as the delimiter string, chunked (memory-efficient) algorithm.
Multiple subsequent separators are collapsed to one occurrence.
The split is performed in chunks of #chunks
to avoid excessive memory consumption.
type(string) :: astring
type(string), allocatable :: strings(:)
logical :: test_passed(1)
astring = '-1-2-3-4-5-6-7-8-'
call astring%split_chunked(tokens=strings, sep='-', chunks=3)
test_passed(1) = (strings(1)//''=='1'.and.strings(2)//''=='2'.and.strings(3)//''=='3'.and.strings(4)//''=='4'.and. &
strings(5)//''=='5'.and.strings(6)//''=='6'.and.strings(7)//''=='7'.and.strings(8)//''=='8')
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(out), | allocatable | :: | tokens(:) |
Tokens substring. |
|
integer, | intent(in) | :: | chunks |
Number of chunks. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
Return a string with all words capitalized, e.g. title case.
Return a string with all words capitalized, e.g. title case.
Multiple subsequent separators are collapsed to one occurence.
type(string) :: astring
logical :: test_passed(1)
astring = 'the Quick Brown fox Jumps over the Lazy Dog.'
test_passed(1) = astring%startcase()//''=='The Quick Brown Fox Jumps Over The Lazy Dog.'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
Start case string.
Return a string with the leading and trailing characters removed.
Return a copy of the string with the leading and trailing characters removed.
Multiple subsequent separators are collapsed to one occurence.
type(string) :: astring
logical :: test_passed(1)
astring = ' Hello World! '
test_passed(1) = astring%strip()//''=='Hello World!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
logical, | intent(in), | optional | :: | remove_nulls |
Remove null characters at the end. |
The stripped string.
Return a string with uppercase chars converted to lowercase and vice versa.
Return a copy of the string with uppercase characters converted to lowercase and vice versa.
type(string) :: astring
logical :: test_passed(1)
astring = ' Hello World! '
test_passed(1) = astring%swapcase()//''==' hELLO wORLD! '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Upper case string.
Return a safe temporary name suitable for temporary file or directories.
Return a safe temporary name suitable for temporary file or directories.
type(string) :: astring
character(len=:), allocatable :: tmpname
logical :: test_passed(5)
tmpname = astring%tempname()
inquire(file=tmpname, exist=test_passed(1))
test_passed(1) = .not.test_passed(1)
tmpname = astring%tempname(is_file=.false.)
inquire(file=tmpname, exist=test_passed(2))
test_passed(2) = .not.test_passed(2)
tmpname = astring%tempname(path='./')
inquire(file=tmpname, exist=test_passed(3))
test_passed(3) = .not.test_passed(3)
astring = 'me-'
tmpname = astring%tempname()
inquire(file=tmpname, exist=test_passed(4))
test_passed(4) = .not.test_passed(4)
tmpname = astring%tempname(prefix='you-')
inquire(file=tmpname, exist=test_passed(5))
test_passed(5) = .not.test_passed(5)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
logical, | intent(in), | optional | :: | is_file |
True if tempname should be used for file (the default). |
|
character(len=*), | intent(in), | optional | :: | prefix |
Name prefix, otherwise self is used (if allocated). |
|
character(len=*), | intent(in), | optional | :: | path |
Path where file/directory should be used, default |
Safe (unique) temporary name.
Cast string to number.
Cast string to integer (I1P).
use penf
type(string) :: astring
integer(I1P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I1P)
test_passed(1) = integer_==127_I1P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I1P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to integer (I2P).
use penf
type(string) :: astring
integer(I2P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I2P)
test_passed(1) = integer_==127_I2P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I2P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to integer (I4P).
use penf
type(string) :: astring
integer(I4P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I4P)
test_passed(1) = integer_==127_I4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I4P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to integer (I8P).
use penf
type(string) :: astring
integer(I8P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I8P)
test_passed(1) = integer_==127_I8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I8P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to real (R8P).
use penf
type(string) :: astring
real(R8P) :: real_
logical :: test_passed(1)
astring = '3.4e9'
real_ = astring%to_number(kind=1._R8P)
test_passed(1) = real_==3.4e9_R8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
real(kind=R8P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to real (R4P).
use penf
type(string) :: astring
real(R4P) :: real_
logical :: test_passed(1)
astring = '3.4e9'
real_ = astring%to_number(kind=1._R4P)
test_passed(1) = real_==3.4e9_R4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
real(kind=R4P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Unescape double backslashes (or custom escaped character).
Unescape double backslashes (or custom escaped character).
type(string) :: astring
logical :: test_passed(2)
astring = '^\\s \\d+\\s*'
test_passed(1) = (astring%unescape(to_unescape='\')//''=='^\s \d+\s*')
test_passed(2) = (astring%unescape(to_unescape='s')//''=='^\s \\d+\s*')
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=1), | intent(in) | :: | to_unescape |
Character to be unescaped. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | unesc |
Character used to unescape. |
Escaped string.
Reduce to one (unique) multiple occurrences of a substring into a string.
Reduce to one (unique) multiple (sequential) occurrences of a substring into a string.
For example the string ‘ ab-cre-cre-ab’ is reduce to ‘ab-cre-ab’ if the substring is ‘-cre’.
Eventual multiple trailing white space are not reduced to one occurrence.
type(string) :: astring
logical :: test_passed(1)
astring = '+++ab-++cre-++cre-ab+++++'
test_passed(1) = astring%unique(substring='+')//''=='+ab-+cre-+cre-ab+'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | substring |
Substring which multiple occurences must be reduced to one. |
String parsed.
Return a string with all uppercase characters.
Return a string with all uppercase characters.
type(string) :: astring
logical :: test_passed(1)
astring = 'Hello WorLD!'
test_passed(1) = astring%upper()//''=='HELLO WORLD!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Upper case string.
Write a single string stream into file.
Write a single string stream into file.
For unformatted read only access='stream'
is supported with new_line as line terminator.
type(string) :: astring
type(string) :: anotherstring
type(string), allocatable :: strings(:)
type(string) :: line(3)
integer :: iostat
character(len=99) :: iomsg
integer :: scratch
integer :: l
logical :: test_passed(8)
line(1) = ' Hello World! '
line(2) = 'How are you? '
line(3) = ' All say: "Fine thanks"'
anotherstring = anotherstring%join(array=line, sep=new_line('a'))
call anotherstring%write_file(file='write_file_test.tmp', iostat=iostat, iomsg=iomsg)
call astring%read_file(file='write_file_test.tmp', iostat=iostat, iomsg=iomsg)
call astring%split(tokens=strings, sep=new_line('a'))
test_passed(1) = (size(strings, dim=1)==size(line, dim=1))
do l=1, size(strings, dim=1)
test_passed(l+1) = (strings(l)==line(l))
enddo
call anotherstring%write_file(file='write_file_test.tmp', form='unformatted', iostat=iostat, iomsg=iomsg)
call astring%read_file(file='write_file_test.tmp', form='unformatted', iostat=iostat, iomsg=iomsg)
call astring%split(tokens=strings, sep=new_line('a'))
test_passed(5) = (size(strings, dim=1)==size(line, dim=1))
do l=1, size(strings, dim=1)
test_passed(l+5) = (strings(l)==line(l))
enddo
open(newunit=scratch, file='write_file_test.tmp')
close(unit=scratch, status='delete')
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | file |
File name. |
||
character(len=*), | intent(in), | optional | :: | form |
Format of unit. |
|
integer, | intent(out), | optional | :: | iostat |
IO status code. |
|
character(len=*), | intent(inout), | optional | :: | iomsg |
IO status message. |
Write line (record) to a connected unit.
Write line (record) to a connected unit.
If the connected unit is unformatted a new_line()
character is added at the end (if necessary) to mark the end of line.
There is no doctests, this being tested by means of write_file doctests.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(len=*), | intent(in), | optional | :: | form |
Format of unit. |
|
integer, | intent(out), | optional | :: | iostat |
IO status code. |
|
character(len=*), | intent(inout), | optional | :: | iomsg |
IO status message. |
Write lines (records) to a connected unit.
Write lines (records) to a connected unit.
This method checks if self contains more than one line (records) and writes them as lines (records).
If the connected unit is unformatted a new_line()
character is added at the end (if necessary) to mark the end of line.
There is no doctests, this being tested by means of write_file doctests.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(len=*), | intent(in), | optional | :: | form |
Format of unit. |
|
integer, | intent(out), | optional | :: | iostat |
IO status code. |
|
character(len=*), | intent(inout), | optional | :: | iomsg |
IO status message. |
Return true if a string ends with a specified suffix.
Return true if a string ends with a specified suffix.
type(string) :: astring
logical :: test_passed(5)
astring = 'Hello WorLD!'
test_passed(1) = astring%end_with(suffix='LD!').eqv..true.
test_passed(2) = astring%end_with(suffix='lD!').eqv..false.
test_passed(3) = astring%end_with(suffix='orLD!', start=5).eqv..true.
test_passed(4) = astring%end_with(suffix='orLD!', start=8, end=12).eqv..true.
test_passed(5) = astring%end_with(suffix='!').eqv..true.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | suffix |
Searched suffix. |
||
integer, | intent(in), | optional | :: | start |
Start position into the string. |
|
integer, | intent(in), | optional | :: | end |
End position into the string. |
|
logical, | intent(in), | optional | :: | ignore_null_eof |
Ignore null character at the end of file. |
Result of the test.
Return true if the string is allocated.
Return true if the string is allocated.
type(string) :: astring
logical :: test_passed(2)
test_passed(1) = astring%is_allocated().eqv..false.
astring = 'hello'
test_passed(2) = astring%is_allocated().eqv..true.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Result of the test.
Return true if all characters in the string are digits.
Return true if all characters in the string are digits.
type(string) :: astring
logical :: test_passed(2)
astring = ' -1212112.3 '
test_passed(1) = astring%is_digit().eqv..false.
astring = '12121123'
test_passed(2) = astring%is_digit().eqv..true.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Result of the test.
Return true if the string contains an integer.
Return true if the string contains an integer.
The regular expression is \s*[\+\-]?\d+([eE]\+?\d+)?\s*
. The parse algorithm is done in stages:
S0 | S1 | S2 | S3 | S4 | S5 | S6 |
---|---|---|---|---|---|---|
\s* |
[\+\-]? |
\d+ |
[eE] |
\+? |
\d+ |
\s* |
Exit on stages-parsing results in:
S0 | S1 | S2 | S3 | S4 | S5 | S6 |
---|---|---|---|---|---|---|
F | F | T | F | F | T | T |
This implementation is courtesy of tomedunn
type(string) :: astring
logical :: test_passed(6)
astring = ' -1212112 '
test_passed(1) = astring%is_integer().eqv..true.
astring = ' -1212112'
test_passed(2) = astring%is_integer(allow_spaces=.false.).eqv..false.
astring = '-1212112 '
test_passed(3) = astring%is_integer(allow_spaces=.false.).eqv..false.
astring = '+2e20'
test_passed(4) = astring%is_integer().eqv..true.
astring = ' -2E13 '
test_passed(5) = astring%is_integer().eqv..true.
astring = ' -2 E13 '
test_passed(6) = astring%is_integer().eqv..false.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
logical, | intent(in), | optional | :: | allow_spaces |
Allow leading-trailing spaces. |
Result of the test.
Return true if all characters in the string are lowercase.
Return true if all characters in the string are lowercase.
type(string) :: astring
logical :: test_passed(3)
astring = ' Hello World'
test_passed(1) = astring%is_lower().eqv..false.
astring = ' HELLO WORLD'
test_passed(2) = astring%is_lower().eqv..false.
astring = ' hello world'
test_passed(3) = astring%is_lower().eqv..true.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Result of the test.
Return true if the string contains a number (real or integer).
Return true if the string contains a number (real or integer).
type(string) :: astring
logical :: test_passed(7)
astring = ' -1212112 '
test_passed(1) = astring%is_number().eqv..true.
astring = ' -121.2112 '
test_passed(2) = astring%is_number().eqv..true.
astring = ' -1212112'
test_passed(3) = astring%is_number(allow_spaces=.false.).eqv..false.
astring = '-12121.12 '
test_passed(4) = astring%is_number(allow_spaces=.false.).eqv..false.
astring = '+2e20'
test_passed(5) = astring%is_number().eqv..true.
astring = ' -2.4E13 '
test_passed(6) = astring%is_number().eqv..true.
astring = ' -2 E13 '
test_passed(7) = astring%is_number().eqv..false.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
logical, | intent(in), | optional | :: | allow_spaces |
Allow leading-trailing spaces. |
Result of the test.
Return true if the string contains an real.
Return true if the string contains a real.
The regular expression is \s*[\+\-]?\d*(|\.?\d*([deDE][\+\-]?\d+)?)\s*
. The parse algorithm is done in stages:
S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | S8 |
---|---|---|---|---|---|---|---|---|
\s* |
[\+\-]? |
\d* |
\.? |
\d* |
[deDE] |
[\+\-]? |
\d* |
\s* |
Exit on stages-parsing results in:
S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | S8 |
---|---|---|---|---|---|---|---|---|
This implementation is courtesy of tomedunn
type(string) :: astring
logical :: test_passed(6)
astring = ' -1212112.d0 '
test_passed(1) = astring%is_real().eqv..true.
astring = ' -1212112.d0'
test_passed(2) = astring%is_real(allow_spaces=.false.).eqv..false.
astring = '-1212112.d0 '
test_passed(3) = astring%is_real(allow_spaces=.false.).eqv..false.
astring = '+2.e20'
test_passed(4) = astring%is_real().eqv..true.
astring = ' -2.01E13 '
test_passed(5) = astring%is_real().eqv..true.
astring = ' -2.01 E13 '
test_passed(6) = astring%is_real().eqv..false.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
logical, | intent(in), | optional | :: | allow_spaces |
Allow leading-trailing spaces. |
Result of the test.
Return true if all characters in the string are uppercase.
Return true if all characters in the string are uppercase.
type(string) :: astring
logical :: test_passed(3)
astring = ' Hello World'
test_passed(1) = astring%is_upper().eqv..false.
astring = ' HELLO WORLD'
test_passed(2) = astring%is_upper().eqv..true.
astring = ' hello world'
test_passed(3) = astring%is_upper().eqv..false.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Result of the test.
Return true if a string starts with a specified prefix.
Return true if a string starts with a specified prefix.
type(string) :: astring
logical :: test_passed(4)
astring = 'Hello WorLD!'
test_passed(1) = astring%start_with(prefix='Hello').eqv..true.
test_passed(2) = astring%start_with(prefix='hell').eqv..false.
test_passed(3) = astring%start_with(prefix='llo Wor', start=3).eqv..true.
test_passed(4) = astring%start_with(prefix='lo W', start=4, end=7).eqv..true.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | prefix |
Searched prefix. |
||
integer, | intent(in), | optional | :: | start |
Start position into the string. |
|
integer, | intent(in), | optional | :: | end |
End position into the string. |
Result of the test.
Assignment operator overloading.
Assignment operator from string input.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(1)
astring = 'hello'
anotherstring = astring
test_passed(1) = astring%chars()==anotherstring%chars()
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from character input.
type(string) :: astring
logical :: test_passed(1)
astring = 'hello'
test_passed(1) = astring%chars()=='hello'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I1P
test_passed(1) = astring%to_number(kind=1_I1P)==127_I1P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I1P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I2P
test_passed(1) = astring%to_number(kind=1_I2P)==127_I2P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I2P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I4P
test_passed(1) = astring%to_number(kind=1_I4P)==127_I4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I4P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I8P
test_passed(1) = astring%to_number(kind=1_I8P)==127_I8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I8P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from real input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 3.021e6_R8P
test_passed(1) = astring%to_number(kind=1._R8P)==3.021e6_R8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
real(kind=R8P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from real input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 3.021e6_R4P
test_passed(1) = astring%to_number(kind=1._R4P)==3.021e6_R4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
real(kind=R4P), | intent(in) | :: | rhs |
Right hand side. |
Concatenation operator overloading.
Concatenation with string.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(1)
astring = 'Hello '
anotherstring = 'Bye bye'
test_passed(1) = astring//anotherstring=='Hello Bye bye'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
test_passed(1) = astring//acharacter=='Hello World!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character (inverted).
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
test_passed(1) = acharacter//astring=='World!Hello '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation operator (string output) overloading.
Concatenation with string.
type(string) :: astring
type(string) :: anotherstring
type(string) :: yetanotherstring
logical :: test_passed(1)
astring = 'Hello '
anotherstring = 'Bye bye'
yetanotherstring = astring.cat.anotherstring
test_passed(1) = yetanotherstring%chars()=='Hello Bye bye'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character.
type(string) :: astring
type(string) :: yetanotherstring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
yetanotherstring = astring.cat.acharacter
test_passed(1) = yetanotherstring%chars()=='Hello World!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character (inverted).
type(string) :: astring
type(string) :: yetanotherstring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
yetanotherstring = acharacter.cat.astring
test_passed(1) = yetanotherstring%chars()=='World!Hello '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Equal operator overloading.
Equal to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = ' one '
anotherstring = 'two'
test_passed(1) = ((astring==anotherstring).eqv..false.)
astring = 'the same '
anotherstring = 'the same '
test_passed(2) = ((astring==anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Equal to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((astring==acharacter).eqv..false.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((astring==acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Equal to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((acharacter==astring).eqv..false.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((acharacter==astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Not equal operator overloading.
Not equal to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = ' one '
anotherstring = 'two'
test_passed(1) = ((astring/=anotherstring).eqv..true.)
astring = 'the same '
anotherstring = 'the same '
test_passed(2) = ((astring/=anotherstring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Not equal to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((astring/=acharacter).eqv..true.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((astring/=acharacter).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Not equal to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((acharacter/=astring).eqv..true.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((acharacter/=astring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower than operator overloading.
Lower than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring<anotherstring).eqv..false.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring<anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring<acharacter).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring<acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter<astring).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter<astring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower equal than operator overloading.
Lower equal than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(3)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring<=anotherstring).eqv..false.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring<=anotherstring).eqv..true.)
astring = 'ONE'
anotherstring = 'ONE'
test_passed(3) = ((astring<=anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower equal than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring<=acharacter).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring<=acharacter).eqv..true.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((astring<=acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower equal than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter<=astring).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter<=astring).eqv..false.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((acharacter<=astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater equal than operator overloading.
Greater equal than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(3)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring>=anotherstring).eqv..true.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring>=anotherstring).eqv..false.)
astring = 'ONE'
anotherstring = 'ONE'
test_passed(3) = ((astring>=anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater equal than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring>=acharacter).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring>=acharacter).eqv..false.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((astring>=acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater equal than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter>=astring).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter>=astring).eqv..true.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((acharacter>=astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater than operator overloading.
Greater than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring>anotherstring).eqv..true.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring>anotherstring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring>acharacter).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring>acharacter).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter>astring).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter>astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Formatted input.
Formatted input.
Change temporary acks: find a more precise length of the input string and avoid the trimming!
Read listdirected with and without delimiters does not work.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(len=*), | intent(in) | :: | iotype |
Edit descriptor. |
||
integer, | intent(in) | :: | v_list(:) |
Edit descriptor list. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(len=*), | intent(inout) | :: | iomsg |
IO status message. |
Formatted output.
Formatted output.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(kind=CK, len=*), | intent(in) | :: | iotype |
Edit descriptor. |
||
integer, | intent(in) | :: | v_list(:) |
Edit descriptor list. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(kind=CK, len=*), | intent(inout) | :: | iomsg |
IO status message. |
Unformatted input.
Unformatted input.
Change temporary acks: find a more precise length of the input string and avoid the trimming!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(kind=CK, len=*), | intent(inout) | :: | iomsg |
IO status message. |
Unformatted output.
Unformatted output.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(kind=CK, len=*), | intent(inout) | :: | iomsg |
IO status message. |
Index replacement.
Return the position of the start of the first occurrence of string substring
as a substring in string
, counting from one.
If substring
is not present in string
, zero is returned. If the back argument is present and true, the return value is
the start of the last occurrence rather than the first.
type(string) :: string1
type(string) :: string2
logical :: test_passed(2)
string1 = 'Hello World Hello!'
string2 = 'llo'
test_passed(1) = string1%index(substring=string2)==index(string='Hello World Hello!', substring='llo')
test_passed(2) = string1%index(substring=string2, back=.true.)==index(string='Hello World Hello!', substring='llo', &
back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | substring |
Searched substring. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Index replacement.
Return the position of the start of the first occurrence of string substring
as a substring in string
, counting from one.
If substring
is not present in string
, zero is returned. If the back argument is present and true, the return value is
the start of the last occurrence rather than the first.
type(string) :: string1
logical :: test_passed(2)
string1 = 'Hello World Hello!'
test_passed(1) = string1%index(substring='llo')==index(string='Hello World Hello!', substring='llo')
test_passed(2) = string1%index(substring='llo', back=.true.)==index(string='Hello World Hello!', substring='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | substring |
Searched substring. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Repeat replacement.
Concatenates several copies of an input string.
type(string) :: astring
astring = 'x'
print "(L1)", astring%repeat(5)//''=='xxxxx'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
String to be repeated. |
||
integer, | intent(in) | :: | ncopies |
Number of string copies. |
Repeated string.
Repeat replacement.
Concatenates several copies of an input string.
type(string) :: astring
astring = 'y'
print "(L1)", astring%repeat('x', 5)//''=='xxxxx'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | rstring |
String to be repeated. |
||
integer, | intent(in) | :: | ncopies |
Number of string copies. |
Repeated string.
Scan replacement.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is in set
.
type(string) :: string1
type(string) :: string2
logical :: test_passed(2)
string1 = 'Hello World Hello!'
string2 = 'llo'
test_passed(1) = string1%scan(set=string2)==scan(string='Hello World Hello!', set='llo')
test_passed(2) = string1%scan(set=string2, back=.true.)==scan(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Scan replacement.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is in set
.
type(string) :: string1
logical :: test_passed(2)
string1 = 'Hello World Hello!'
test_passed(1) = string1%scan(set='llo')==scan(string='Hello World Hello!', set='llo')
test_passed(2) = string1%scan(set='llo', back=.true.)==scan(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Verify replacement.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is not
in set
. If all characters of string
are found in set
, the result is zero.
type(string) :: string1
type(string) :: string2
logical :: test_passed(2)
string1 = 'Hello World Hello!'
string2 = 'llo'
test_passed(1) = string1%verify(set=string2)==verify(string='Hello World Hello!', set='llo')
test_passed(2) = string1%verify(set=string2, back=.true.)==verify(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Verify replacement.
Return the leftmost (if back
is either absent or equals false, otherwise the rightmost) character of string that is not
in set
. If all characters of string
are found in set
, the result is zero.
type(string) :: string1
logical :: test_passed(2)
string1 = 'Hello World Hello!'
test_passed(1) = string1%verify(set='llo')==verify(string='Hello World Hello!', set='llo')
test_passed(2) = string1%verify(set='llo', back=.true.)==verify(string='Hello World Hello!', set='llo', back=.true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | set |
Searched set. |
||
logical, | intent(in), | optional | :: | back |
Start of the last occurrence rather than the first. |
Result of the search.
Colorize and stylize strings.
Colorize and stylize strings, DEFAULT kind.
type(string) :: astring
astring = 'say all Hello WorLD!'
print '(L1)', astring%colorize(color_fg='red')=='[31msay all Hello WorLD![0m'
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in), | optional | :: | color_fg |
Foreground color definition. |
|
character(len=*), | intent(in), | optional | :: | color_bg |
Background color definition. |
|
character(len=*), | intent(in), | optional | :: | style |
Style definition. |
Colorized string.
Glob search (character output).
Glob search (character output), finds all the pathnames matching a given pattern according to the rules used by the Unix shell.
Method not portable: works only on Unix/GNU Linux OS.
type(string) :: astring
character(len=:), allocatable :: alist_chr(:)
integer, parameter :: Nf=5
character(14) :: files(1:Nf)
integer :: file_unit
integer :: f
integer :: ff
logical :: test_passed
do f=1, Nf
files(f) = astring%tempname(prefix='foo-')
open(newunit=file_unit, file=files(f))
write(file_unit, *)f
close(unit=file_unit)
enddo
call astring%glob(pattern='foo-*', list=alist_chr)
do f=1, Nf
open(newunit=file_unit, file=files(f))
close(unit=file_unit, status='delete')
enddo
test_passed = .false.
outer_chr: do f=1, size(alist_chr, dim=1)
do ff=1, Nf
test_passed = alist_chr(f) == files(ff)
if (test_passed) cycle outer_chr
enddo
enddo outer_chr
print '(L1)', test_passed
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | pattern |
Given pattern. |
||
character(len=:), | intent(out), | allocatable | :: | list(:) |
List of matching pathnames. |
Glob search (string output).
Glob search (string output), finds all the pathnames matching a given pattern according to the rules used by the Unix shell.
Method not portable: works only on Unix/GNU Linux OS.
type(string) :: astring
type(string), allocatable :: alist_str(:)
integer, parameter :: Nf=5
character(14) :: files(1:Nf)
integer :: file_unit
integer :: f
integer :: ff
logical :: test_passed
do f=1, Nf
files(f) = astring%tempname(prefix='foo-')
open(newunit=file_unit, file=files(f))
write(file_unit, *)f
close(unit=file_unit)
enddo
call astring%glob(pattern='foo-*', list=alist_str)
do f=1, Nf
open(newunit=file_unit, file=files(f))
close(unit=file_unit, status='delete')
enddo
test_passed = .false.
outer_str: do f=1, size(alist_str, dim=1)
do ff=1, Nf
test_passed = alist_str(f) == files(ff)
if (test_passed) cycle outer_str
enddo
enddo outer_str
print '(L1)', test_passed
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | pattern |
Given pattern. |
||
type(string), | intent(out), | allocatable | :: | list(:) |
List of matching pathnames. |
Insert substring into string at a specified position.
Insert substring into string at a specified position.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(5)
astring = 'this is string example wow!!!'
anotherstring = '... '
test_passed(1) = astring%insert(substring=anotherstring, pos=1)//''=='... this is string example wow!!!'
test_passed(2) = astring%insert(substring=anotherstring, pos=23)//''=='this is string example... wow!!!'
test_passed(3) = astring%insert(substring=anotherstring, pos=29)//''=='this is string example wow!!!... '
test_passed(4) = astring%insert(substring=anotherstring, pos=-1)//''=='... this is string example wow!!!'
test_passed(5) = astring%insert(substring=anotherstring, pos=100)//''=='this is string example wow!!!... '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | substring |
Substring. |
||
integer, | intent(in) | :: | pos |
Position from which insert substring. |
Inserted string.
Insert substring into string at a specified position.
Insert substring into string at a specified position.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(5)
astring = 'this is string example wow!!!'
acharacter = '... '
test_passed(1) = astring%insert(substring=acharacter, pos=1)//''=='... this is string example wow!!!'
test_passed(2) = astring%insert(substring=acharacter, pos=23)//''=='this is string example... wow!!!'
test_passed(3) = astring%insert(substring=acharacter, pos=29)//''=='this is string example wow!!!... '
test_passed(4) = astring%insert(substring=acharacter, pos=-1)//''=='... this is string example wow!!!'
test_passed(5) = astring%insert(substring=acharacter, pos=100)//''=='this is string example wow!!!... '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(len=*), | intent(in) | :: | substring |
Substring. |
||
integer, | intent(in) | :: | pos |
Position from which insert substring. |
Inserted string.
Return join string of an array of strings.
Return a string that is a join of an array of strings.
The join-separator is set equals to self if self has a value or it is set to a null string ‘’. This value can be overridden passing a custom separator.
type(string) :: astring
type(string) :: strings(3)
logical :: test_passed(5)
strings(1) = 'one'
strings(2) = 'two'
strings(3) = 'three'
test_passed(1) = (astring%join(array=strings)//''==strings(1)//strings(2)//strings(3))
test_passed(2) = (astring%join(array=strings, sep='-')//''==strings(1)//'-'//strings(2)//'-'//strings(3))
call strings(1)%free
strings(2) = 'two'
strings(3) = 'three'
test_passed(3) = (astring%join(array=strings, sep='-')//''==strings(2)//'-'//strings(3))
strings(1) = 'one'
strings(2) = 'two'
call strings(3)%free
test_passed(4) = (astring%join(array=strings, sep='-')//''==strings(1)//'-'//strings(2))
strings(1) = 'one'
call strings(2)%free
strings(3) = 'three'
test_passed(5) = (astring%join(array=strings, sep='-')//''==strings(1)//'-'//strings(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
type(string), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
The join of array.
Return join string of an array of characters.
Return a string that is a join of an array of characters.
The join-separator is set equals to self if self has a value or it is set to a null string ‘’. This value can be overridden passing a custom separator.
type(string) :: astring
character(5) :: characters(3)
logical :: test_passed(6)
characters(1) = 'one'
characters(2) = 'two'
characters(3) = 'three'
test_passed(1) = (astring%join(array=characters)//''==characters(1)//characters(2)//characters(3))
test_passed(2) = (astring%join(array=characters, sep='-')//''==characters(1)//'-'//characters(2)//'-'//characters(3))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(3) = (astring%join(array=characters, sep='-')//''==characters(2)//'-'//characters(3))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(4) = (astring%join(array=characters, sep='-')//''==characters(1)//'-'//characters(2))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(5) = (astring%join(array=characters, sep='-')//''==characters(1)//'-'//characters(3))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = 'three'
astring = '_'
test_passed(6) = (astring%join(array=characters)//''==characters(1)//'_'//characters(2)//'_'//characters(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
The join of array.
Return join string of an array of strings.
Return a string that is a join of an array of strings.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified.
type(string) :: strings(3)
logical :: test_passed(5)
strings(1) = 'one'
strings(2) = 'two'
strings(3) = 'three'
test_passed(1) = (strjoin(array=strings)//''==strings(1)//strings(2)//strings(3))
test_passed(2) = (strjoin(array=strings, sep='-')//''==strings(1)//'-'//strings(2)//'-'//strings(3))
call strings(1)%free
strings(2) = 'two'
strings(3) = 'three'
test_passed(3) = (strjoin(array=strings, sep='-')//''==strings(2)//'-'//strings(3))
strings(1) = 'one'
strings(2) = 'two'
call strings(3)%free
test_passed(4) = (strjoin(array=strings, sep='-')//''==strings(1)//'-'//strings(2))
strings(1) = 'one'
call strings(2)%free
strings(3) = 'three'
test_passed(5) = (strjoin(array=strings, sep='-')//''==strings(1)//'-'//strings(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
The join of array.
Return join string of an array of strings.
Return a string that is a join of an array of characters.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified. The trim function is applied to array items if optional logical is_trim variable isn’t set to .false.
character(5) :: characters(3)
logical :: test_passed(13)
characters(1) = 'one'
characters(2) = 'two'
characters(3) = 'three'
test_passed(1) = (strjoin(array=characters)//''==trim(characters(1))//trim(characters(2))//trim(characters(3)))
test_passed(2) = (strjoin(array=characters, sep='-')//''==trim(characters(1))//'-'//trim(characters(2))//'-'//trim(characters(3)))
test_passed(3) = ( strjoin(array=characters, is_trim=.false.)//''==characters(1)//characters(2)//characters(3))
test_passed(4) = ( strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(1)//'-'//characters(2)//'-'//characters(3))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(5) = (strjoin(array=characters)//''==trim(characters(2))//trim(characters(3)))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(6) = (strjoin(array=characters)//''==trim(characters(1))//trim(characters(2)))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(7) = (strjoin(array=characters)//''==trim(characters(1))//trim(characters(3)))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(8) = (strjoin(array=characters, sep='-')//''==trim(characters(2))//'-'//trim(characters(3)))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(9) = (strjoin(array=characters, sep='-')//''==trim(characters(1))//'-'//trim(characters(2)))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(10) = (strjoin(array=characters, sep='-')//''==trim(characters(1))//'-'//trim(characters(3)))
characters(1) = ''
characters(2) = 'two'
characters(3) = 'three'
test_passed(11) = (strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(2)//'-'//characters(3))
characters(1) = 'one'
characters(2) = 'two'
characters(3) = ''
test_passed(12) = (strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(1)//'-'//characters(2))
characters(1) = 'one'
characters(2) = ''
characters(3) = 'three'
test_passed(13) = (strjoin(array=characters, sep='-', is_trim=.false.)//''==characters(1)//'-'//characters(3))
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | array(1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
|
logical, | intent(in), | optional | :: | is_trim |
Flag to setup trim character or not |
The join of array.
Return join 1D string array of an 2D array of strings in columns or rows.
Return a string that is a join of columns or rows of an array of strings.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified. The is_col is setup the direction of join: within default columns (.true.) or rows(.false.).
type(string), allocatable :: strings_arr(:, :)
logical :: test_passed(5)
strings_arr = reshape( source = &
[string('one'), string('two'), string('three'), &
string('ONE'), string('TWO'), string('THREE')], &
shape = [3, 2] )
test_passed(1) = all( strjoin(array=strings_arr) == &
reshape([string('onetwothree'), string('ONETWOTHREE')], &
shape = [2]) )
test_passed(2) = all( strjoin(array=strings_arr, sep='_') == &
reshape([string('one_two_three'), string('ONE_TWO_THREE')], &
shape = [2]) )
test_passed(3) = all( strjoin(array=strings_arr, is_col=.false.) == &
reshape([string('oneONE'), string('twoTWO'), string('threeTHREE')], &
shape = [3]) )
test_passed(4) = all( strjoin(array=strings_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), string('two_TWO'), string('three_THREE')], &
shape = [3]) )
call strings_arr(2, 1)%free
test_passed(5) = all( strjoin(array=strings_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), string('TWO'), string('three_THREE')], &
shape = [3]) )
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | array(1:,1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
|
logical, | intent(in), | optional | :: | is_col |
Direction: ‘columns’ if .true. or ‘rows’ if .false. |
The join of array.
Return join 1D string array of an 2D array of characters in columns or rows.
Return a string that is a join of columns or rows of an array of characters.
The join-separator is set equals to a null string ‘’ if custom separator isn’t specified. The trim function is applied to array items if optional logical is_trim variable isn’t set to .false. The is_col is setup the direction of join: within default columns (.true.) or rows(.false.).
character(len=10) :: chars_arr(3, 2)
logical :: test_passed(9)
chars_arr(:, 1) = ['one ', 'two ', 'three ']
chars_arr(:, 2) = ['ONE ', 'TWO ', 'THREE ']
test_passed(1) = all( strjoin(array=chars_arr) == &
reshape([string('onetwothree'), string('ONETWOTHREE')], &
shape = [2]) )
test_passed(2) = all( strjoin(array=chars_arr, is_trim=.false.) == &
reshape([string('one two three '), &
string('ONE TWO THREE ')], &
shape = [2]) )
test_passed(3) = all( strjoin(array=chars_arr, sep='_') == &
reshape([string('one_two_three'), string('ONE_TWO_THREE')], &
shape = [2]) )
test_passed(4) = all( strjoin(array=chars_arr, sep='_', is_trim=.false.) == &
reshape([string('one _two _three '), &
string('ONE _TWO _THREE ')], &
shape = [2]) )
test_passed(5) = all( strjoin(array=chars_arr, is_col=.false.) == &
reshape([string('oneONE'), string('twoTWO'), string('threeTHREE')], &
shape = [3]) )
test_passed(6) = all( strjoin(array=chars_arr, is_trim=.false., is_col=.false.) == &
reshape([string('one ONE '), &
string('two TWO '), &
string('three THREE ')], &
shape = [3]) )
test_passed(7) = all( strjoin(array=chars_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), string('two_TWO'), string('three_THREE')], &
shape = [3]) )
test_passed(8) = all( strjoin(array=chars_arr, sep='_', is_trim=.false., is_col=.false.) == &
reshape([string('one _ONE '), &
string('two _TWO '), &
string('three _THREE ')], &
shape = [3]) )
chars_arr(2,1) = ''
test_passed(9) = all( strjoin(array=chars_arr, sep='_', is_col=.false.) == &
reshape([string('one_ONE'), &
string('TWO'), &
string('three_THREE')], &
shape = [3]) )
print '(L1)', all(test_passed)
all items of character array have equal lengths
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | array(1:,1:) |
Array to be joined. |
||
character(kind=CK, len=*), | intent(in), | optional | :: | sep |
Separator. |
|
logical, | intent(in), | optional | :: | is_trim |
Flag to setup trim character or not |
|
logical, | intent(in), | optional | :: | is_col |
Direction: ‘columns’ if .true. or ‘rows’ if .false. |
The join of array.
Cast string to integer.
Cast string to integer (I1P).
use penf
type(string) :: astring
integer(I1P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I1P)
test_passed(1) = integer_==127_I1P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I1P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to integer.
Cast string to integer (I2P).
use penf
type(string) :: astring
integer(I2P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I2P)
test_passed(1) = integer_==127_I2P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I2P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to integer.
Cast string to integer (I4P).
use penf
type(string) :: astring
integer(I4P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I4P)
test_passed(1) = integer_==127_I4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I4P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to integer.
Cast string to integer (I8P).
use penf
type(string) :: astring
integer(I8P) :: integer_
logical :: test_passed(1)
astring = '127'
integer_ = astring%to_number(kind=1_I8P)
test_passed(1) = integer_==127_I8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
integer(kind=I8P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to real.
Cast string to real (R4P).
use penf
type(string) :: astring
real(R4P) :: real_
logical :: test_passed(1)
astring = '3.4e9'
real_ = astring%to_number(kind=1._R4P)
test_passed(1) = real_==3.4e9_R4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
real(kind=R4P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to real.
Cast string to real (R8P).
use penf
type(string) :: astring
real(R8P) :: real_
logical :: test_passed(1)
astring = '3.4e9'
real_ = astring%to_number(kind=1._R8P)
test_passed(1) = real_==3.4e9_R8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
real(kind=R8P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Cast string to real.
Cast string to real (R16P).
use penf
type(string) :: astring
real(R16P) :: real_
logical :: test_passed(1)
astring = '3.4e9'
real_ = astring%to_number(kind=1._R16P)
test_passed(1) = real_==3.4e9_R16P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
real(kind=R16P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
Assignment operator from string input.
Assignment operator from string input.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(1)
astring = 'hello'
anotherstring = astring
test_passed(1) = astring%chars()==anotherstring%chars()
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from character input.
Assignment operator from character input.
type(string) :: astring
logical :: test_passed(1)
astring = 'hello'
test_passed(1) = astring%chars()=='hello'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I1P
test_passed(1) = astring%to_number(kind=1_I1P)==127_I1P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I1P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I2P
test_passed(1) = astring%to_number(kind=1_I2P)==127_I2P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I2P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I4P
test_passed(1) = astring%to_number(kind=1_I4P)==127_I4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I4P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from integer input.
Assignment operator from integer input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 127_I8P
test_passed(1) = astring%to_number(kind=1_I8P)==127_I8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
integer(kind=I8P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from real input.
Assignment operator from real input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 3.021e6_R4P
test_passed(1) = astring%to_number(kind=1._R4P)==3.021e6_R4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
real(kind=R4P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from real input.
Assignment operator from real input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 3.021e6_R8P
test_passed(1) = astring%to_number(kind=1._R8P)==3.021e6_R8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
real(kind=R8P), | intent(in) | :: | rhs |
Right hand side. |
Assignment operator from real input.
Assignment operator from real input.
use penf
type(string) :: astring
logical :: test_passed(1)
astring = 3.021e6_R8P
test_passed(1) = astring%to_number(kind=1._R8P)==3.021e6_R8P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | lhs |
Left hand side. |
||
real(kind=R16P), | intent(in) | :: | rhs |
Right hand side. |
Concatenation with string.
Concatenation with string.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(1)
astring = 'Hello '
anotherstring = 'Bye bye'
test_passed(1) = astring//anotherstring=='Hello Bye bye'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character.
Concatenation with character.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
test_passed(1) = astring//acharacter=='Hello World!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character (inverted).
Concatenation with character (inverted).
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
test_passed(1) = acharacter//astring=='World!Hello '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with string (string output).
Concatenation with string.
type(string) :: astring
type(string) :: anotherstring
type(string) :: yetanotherstring
logical :: test_passed(1)
astring = 'Hello '
anotherstring = 'Bye bye'
yetanotherstring = astring.cat.anotherstring
test_passed(1) = yetanotherstring%chars()=='Hello Bye bye'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character (string output).
Concatenation with character.
type(string) :: astring
type(string) :: yetanotherstring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
yetanotherstring = astring.cat.acharacter
test_passed(1) = yetanotherstring%chars()=='Hello World!'
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Concatenation with character (inverted, string output).
Concatenation with character (inverted).
type(string) :: astring
type(string) :: yetanotherstring
character(len=:), allocatable :: acharacter
logical :: test_passed(1)
astring = 'Hello '
acharacter = 'World!'
yetanotherstring = acharacter.cat.astring
test_passed(1) = yetanotherstring%chars()=='World!Hello '
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Concatenated string.
Equal to string logical operator.
Equal to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = ' one '
anotherstring = 'two'
test_passed(1) = ((astring==anotherstring).eqv..false.)
astring = 'the same '
anotherstring = 'the same '
test_passed(2) = ((astring==anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Equal to character logical operator.
Equal to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((astring==acharacter).eqv..false.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((astring==acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Equal to character (inverted) logical operator.
Equal to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((acharacter==astring).eqv..false.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((acharacter==astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Not equal to string logical operator.
Not equal to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = ' one '
anotherstring = 'two'
test_passed(1) = ((astring/=anotherstring).eqv..true.)
astring = 'the same '
anotherstring = 'the same '
test_passed(2) = ((astring/=anotherstring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Not equal to character logical operator.
Not equal to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((astring/=acharacter).eqv..true.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((astring/=acharacter).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Not equal to character (inverted) logical operator.
Not equal to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = ' one '
acharacter = 'three'
test_passed(1) = ((acharacter/=astring).eqv..true.)
astring = 'the same '
acharacter = 'the same '
test_passed(2) = ((acharacter/=astring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower than to string logical operator.
Lower than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring<anotherstring).eqv..false.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring<anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower than to character logical operator.
Lower than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring<acharacter).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring<acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower than to character (inverted) logical operator.
Lower than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter<astring).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter<astring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower equal than to string logical operator.
Lower equal than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(3)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring<=anotherstring).eqv..false.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring<=anotherstring).eqv..true.)
astring = 'ONE'
anotherstring = 'ONE'
test_passed(3) = ((astring<=anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower equal than to character logical operator.
Lower equal than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring<=acharacter).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring<=acharacter).eqv..true.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((astring<=acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Lower equal than to character (inverted) logical operator.
Lower equal than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter<=astring).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter<=astring).eqv..false.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((acharacter<=astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater equal than to string logical operator.
Greater equal than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(3)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring>=anotherstring).eqv..true.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring>=anotherstring).eqv..false.)
astring = 'ONE'
anotherstring = 'ONE'
test_passed(3) = ((astring>=anotherstring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater equal than to character logical operator.
Greater equal than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring>=acharacter).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring>=acharacter).eqv..false.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((astring>=acharacter).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater equal than to character (inverted) logical operator.
Greater equal than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(3)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter>=astring).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter>=astring).eqv..true.)
astring = 'ONE'
acharacter = 'ONE'
test_passed(3) = ((acharacter>=astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater than to string logical operator.
Greater than to string logical operator.
type(string) :: astring
type(string) :: anotherstring
logical :: test_passed(2)
astring = 'one'
anotherstring = 'ONE'
test_passed(1) = ((astring>anotherstring).eqv..true.)
astring = 'ONE'
anotherstring = 'one'
test_passed(2) = ((astring>anotherstring).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
type(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater than to character logical operator.
Greater than to character logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((astring>acharacter).eqv..true.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((astring>acharacter).eqv..false.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | lhs |
Left hand side. |
||
character(kind=CK, len=*), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Greater than to character (inverted) logical operator.
Greater than to character (inverted) logical operator.
type(string) :: astring
character(len=:), allocatable :: acharacter
logical :: test_passed(2)
astring = 'one'
acharacter = 'ONE'
test_passed(1) = ((acharacter>astring).eqv..false.)
astring = 'ONE'
acharacter = 'one'
test_passed(2) = ((acharacter>astring).eqv..true.)
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=CK, len=*), | intent(in) | :: | lhs |
Left hand side. |
||
class(string), | intent(in) | :: | rhs |
Right hand side. |
Opreator test result.
Formatted input.
Formatted input.
Change temporary acks: find a more precise length of the input string and avoid the trimming!
Read listdirected with and without delimiters does not work.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(len=*), | intent(in) | :: | iotype |
Edit descriptor. |
||
integer, | intent(in) | :: | v_list(:) |
Edit descriptor list. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(len=*), | intent(inout) | :: | iomsg |
IO status message. |
Read a delimited input.
Read a delimited string from a unit connected for formatted input.
If the closing delimiter is followed by end of record, then we return end of record.
This does not need a doctest, it being tested by [[string::read_formatted]].
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(out) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(kind=CK, len=1), | intent(in) | :: | delim |
String delimiter. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(kind=CK, len=*), | intent(inout) | :: | iomsg |
IO status message. |
Read an undelimited input.
Read an undelimited string up until end of record or a character from a set of terminators is encountered.
If a terminator is encountered, the file position will be at that terminating character. If end of record is encountered, the file remains at end of record.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(kind=CK, len=*), | intent(in) | :: | terminators |
Characters that are considered to terminate the string. Blanks in this string are meaningful. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(len=*), | intent(inout) | :: | iomsg |
IO status message. |
Read an undelimited list directed input.
Read an undelimited (no leading apostrophe or double quote) character value according to the rules for list directed input.
A blank, comma/semicolon (depending on the decimal mode), slash or end of record terminates the string.
If input is terminated by end of record, then this procedure returns an end-of-record condition.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(len=*), | intent(inout) | :: | iomsg |
IO status message. |
Formatted output.
Formatted output.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
character(kind=CK, len=*), | intent(in) | :: | iotype |
Edit descriptor. |
||
integer, | intent(in) | :: | v_list(:) |
Edit descriptor list. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(kind=CK, len=*), | intent(inout) | :: | iomsg |
IO status message. |
Unformatted input.
Unformatted input.
Change temporary acks: find a more precise length of the input string and avoid the trimming!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(inout) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(kind=CK, len=*), | intent(inout) | :: | iomsg |
IO status message. |
Unformatted output.
Unformatted output.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | dtv |
The string. |
||
integer, | intent(in) | :: | unit |
Logical unit. |
||
integer, | intent(out) | :: | iostat |
IO status code. |
||
character(kind=CK, len=*), | intent(inout) | :: | iomsg |
IO status message. |
Replace the first occurrence of substring old by new.
Return a string with the first occurrence of substring old replaced by new.
The doctest is not necessary, this being tested by replace.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
character(kind=CK, len=*), | intent(in) | :: | old |
Old substring. |
||
character(kind=CK, len=*), | intent(in) | :: | new |
New substring. |
The string with old replaced by new.
type :: string
!< OOP designed string class.
character(kind=CK, len=:), allocatable :: raw !< Raw data.
contains
! public methods
! builtins replacements
procedure, pass(self) :: adjustl => sadjustl !< Adjustl replacement.
procedure, pass(self) :: adjustr => sadjustr !< Adjustr replacement.
procedure, pass(self) :: count => scount !< Count replacement.
generic :: index => sindex_string_string, &
sindex_string_character !< Index replacement.
procedure, pass(self) :: len => slen !< Len replacement.
procedure, pass(self) :: len_trim => slen_trim !< Len_trim replacement.
generic :: repeat => srepeat_string_string, &
srepeat_character_string !< Repeat replacement.
generic :: scan => sscan_string_string, &
sscan_string_character !< Scan replacement.
procedure, pass(self) :: trim => strim !< Trim replacement.
generic :: verify => sverify_string_string, &
sverify_string_character !< Verify replacement.
! auxiliary methods
procedure, pass(self) :: basedir !< Return the base directory name of a string containing a file name.
procedure, pass(self) :: basename !< Return the base file name of a string containing a file name.
procedure, pass(self) :: camelcase !< Return a string with all words capitalized without spaces.
procedure, pass(self) :: capitalize !< Return a string with its first character capitalized and the rest lowercased.
procedure, pass(self) :: chars !< Return the raw characters data.
generic :: colorize => &
colorize_str !< Colorize and stylize strings.
procedure, pass(self) :: decode !< Decode string.
procedure, pass(self) :: encode !< Encode string.
procedure, pass(self) :: escape !< Escape backslashes (or custom escape character).
procedure, pass(self) :: extension !< Return the extension of a string containing a file name.
procedure, pass(self) :: fill !< Pad string on the left (or right) with zeros (or other char) to fill width.
procedure, pass(self) :: free !< Free dynamic memory.
generic :: glob => &
glob_character, &
glob_string !< Glob search, finds all the pathnames matching a given pattern.
generic :: insert => &
insert_string, &
insert_character !< Insert substring into string at a specified position.
generic :: join => &
join_strings, &
join_characters !< Return a string that is a join of an array of strings or characters.
generic :: strjoin => &
strjoin_strings, &
strjoin_characters, &
strjoin_strings_array, &
strjoin_characters_array !< Return a string that is a join of an array of strings or characters;
!< Return join 1D string array of an 2D array of strings or characters in columns or rows.
procedure, pass(self) :: lower !< Return a string with all lowercase characters.
procedure, pass(self) :: partition !< Split string at separator and return the 3 parts (before, the separator and after).
procedure, pass(self) :: read_file !< Read a file a single string stream.
procedure, pass(self) :: read_line !< Read line (record) from a connected unit.
procedure, pass(self) :: read_lines !< Read (all) lines (records) from a connected unit as a single ascii stream.
procedure, pass(self) :: replace !< Return a string with all occurrences of substring old replaced by new.
procedure, pass(self) :: reverse !< Return a reversed string.
procedure, pass(self) :: search !< Search for *tagged* record into string.
procedure, pass(self) :: slice !< Return the raw characters data sliced.
procedure, pass(self) :: snakecase !< Return a string with all words lowercase separated by "_".
procedure, pass(self) :: split !< Return a list of substring in the string, using sep as the delimiter string.
procedure, pass(self) :: split_chunked !< Return a list of substring in the string, using sep as the delimiter string.
procedure, pass(self) :: startcase !< Return a string with all words capitalized, e.g. title case.
procedure, pass(self) :: strip !< Return a string with the leading and trailing characters removed.
procedure, pass(self) :: swapcase !< Return a string with uppercase chars converted to lowercase and vice versa.
procedure, pass(self) :: tempname !< Return a safe temporary name suitable for temporary file or directories.
generic :: to_number => &
to_integer_I1P,&
#ifndef _NVF
to_integer_I2P,&
#endif
to_integer_I4P,&
to_integer_I8P,&
#if defined _R16P
to_real_R16P, &
#endif
to_real_R8P, &
to_real_R4P !< Cast string to number.
procedure, pass(self) :: unescape !< Unescape double backslashes (or custom escaped character).
procedure, pass(self) :: unique !< Reduce to one (unique) multiple occurrences of a substring into a string.
procedure, pass(self) :: upper !< Return a string with all uppercase characters.
procedure, pass(self) :: write_file !< Write a single string stream into file.
procedure, pass(self) :: write_line !< Write line (record) to a connected unit.
procedure, pass(self) :: write_lines !< Write lines (records) to a connected unit.
! inquire methods
procedure, pass(self) :: end_with !< Return true if a string ends with a specified suffix.
procedure, pass(self) :: is_allocated !< Return true if the string is allocated.
procedure, pass(self) :: is_digit !< Return true if all characters in the string are digits.
procedure, pass(self) :: is_integer !< Return true if the string contains an integer.
procedure, pass(self) :: is_lower !< Return true if all characters in the string are lowercase.
procedure, pass(self) :: is_number !< Return true if the string contains a number (real or integer).
procedure, pass(self) :: is_real !< Return true if the string contains an real.
procedure, pass(self) :: is_upper !< Return true if all characters in the string are uppercase.
procedure, pass(self) :: start_with !< Return true if a string starts with a specified prefix.
! operators
generic :: assignment(=) => string_assign_string, &
string_assign_character, &
string_assign_integer_I1P, &
string_assign_integer_I2P, &
string_assign_integer_I4P, &
string_assign_integer_I8P, &
#if defined _R16P
string_assign_real_R16P, &
#endif
string_assign_real_R8P, &
string_assign_real_R4P !< Assignment operator overloading.
generic :: operator(//) => string_concat_string, &
string_concat_character, &
character_concat_string !< Concatenation operator overloading.
generic :: operator(.cat.) => string_concat_string_string, &
string_concat_character_string, &
character_concat_string_string !< Concatenation operator (string output) overloading.
generic :: operator(==) => string_eq_string, &
string_eq_character, &
character_eq_string !< Equal operator overloading.
generic :: operator(/=) => string_ne_string, &
string_ne_character, &
character_ne_string !< Not equal operator overloading.
generic :: operator(<) => string_lt_string, &
string_lt_character, &
character_lt_string !< Lower than operator overloading.
generic :: operator(<=) => string_le_string, &
string_le_character, &
character_le_string !< Lower equal than operator overloading.
generic :: operator(>=) => string_ge_string, &
string_ge_character, &
character_ge_string !< Greater equal than operator overloading.
generic :: operator(>) => string_gt_string, &
string_gt_character, &
character_gt_string !< Greater than operator overloading.
! IO
generic :: read(formatted) => read_formatted !< Formatted input.
generic :: write(formatted) => write_formatted !< Formatted output.
generic :: read(unformatted) => read_unformatted !< Unformatted input.
generic :: write(unformatted) => write_unformatted !< Unformatted output.
! private methods
! builtins replacements
procedure, private, pass(self) :: sindex_string_string !< Index replacement.
procedure, private, pass(self) :: sindex_string_character !< Index replacement.
procedure, private, pass(self) :: srepeat_string_string !< Repeat replacement.
procedure, private, nopass :: srepeat_character_string !< Repeat replacement.
procedure, private, pass(self) :: sscan_string_string !< Scan replacement.
procedure, private, pass(self) :: sscan_string_character !< Scan replacement.
procedure, private, pass(self) :: sverify_string_string !< Verify replacement.
procedure, private, pass(self) :: sverify_string_character !< Verify replacement.
! auxiliary methods
procedure, private, pass(self) :: colorize_str !< Colorize and stylize strings.
procedure, private, pass(self) :: glob_character !< Glob search (character output).
procedure, private, pass(self) :: glob_string !< Glob search (string output).
procedure, private, pass(self) :: insert_string !< Insert substring into string at a specified position.
procedure, private, pass(self) :: insert_character !< Insert substring into string at a specified position.
procedure, private, pass(self) :: join_strings !< Return join string of an array of strings.
procedure, private, pass(self) :: join_characters !< Return join string of an array of characters.
procedure, private, nopass :: strjoin_strings !< Return join string of an array of strings.
procedure, private, nopass :: strjoin_characters !< Return join string of an array of strings.
procedure, private, nopass :: strjoin_strings_array !< Return join 1D string array of an 2D array of strings in columns or rows.
procedure, private, nopass :: strjoin_characters_array !< Return join 1D string array of an 2D array of characters in columns or rows.
procedure, private, pass(self) :: to_integer_I1P !< Cast string to integer.
#ifndef _NVF
procedure, private, pass(self) :: to_integer_I2P !< Cast string to integer.
#endif
procedure, private, pass(self) :: to_integer_I4P !< Cast string to integer.
procedure, private, pass(self) :: to_integer_I8P !< Cast string to integer.
procedure, private, pass(self) :: to_real_R4P !< Cast string to real.
procedure, private, pass(self) :: to_real_R8P !< Cast string to real.
procedure, private, pass(self) :: to_real_R16P !< Cast string to real.
! assignments
procedure, private, pass(lhs) :: string_assign_string !< Assignment operator from string input.
procedure, private, pass(lhs) :: string_assign_character !< Assignment operator from character input.
procedure, private, pass(lhs) :: string_assign_integer_I1P !< Assignment operator from integer input.
procedure, private, pass(lhs) :: string_assign_integer_I2P !< Assignment operator from integer input.
procedure, private, pass(lhs) :: string_assign_integer_I4P !< Assignment operator from integer input.
procedure, private, pass(lhs) :: string_assign_integer_I8P !< Assignment operator from integer input.
procedure, private, pass(lhs) :: string_assign_real_R4P !< Assignment operator from real input.
procedure, private, pass(lhs) :: string_assign_real_R8P !< Assignment operator from real input.
procedure, private, pass(lhs) :: string_assign_real_R16P !< Assignment operator from real input.
! concatenation operators
procedure, private, pass(lhs) :: string_concat_string !< Concatenation with string.
procedure, private, pass(lhs) :: string_concat_character !< Concatenation with character.
procedure, private, pass(rhs) :: character_concat_string !< Concatenation with character (inverted).
procedure, private, pass(lhs) :: string_concat_string_string !< Concatenation with string (string output).
procedure, private, pass(lhs) :: string_concat_character_string !< Concatenation with character (string output).
procedure, private, pass(rhs) :: character_concat_string_string !< Concatenation with character (inverted, string output).
! logical operators
procedure, private, pass(lhs) :: string_eq_string !< Equal to string logical operator.
procedure, private, pass(lhs) :: string_eq_character !< Equal to character logical operator.
procedure, private, pass(rhs) :: character_eq_string !< Equal to character (inverted) logical operator.
procedure, private, pass(lhs) :: string_ne_string !< Not equal to string logical operator.
procedure, private, pass(lhs) :: string_ne_character !< Not equal to character logical operator.
procedure, private, pass(rhs) :: character_ne_string !< Not equal to character (inverted) logical operator.
procedure, private, pass(lhs) :: string_lt_string !< Lower than to string logical operator.
procedure, private, pass(lhs) :: string_lt_character !< Lower than to character logical operator.
procedure, private, pass(rhs) :: character_lt_string !< Lower than to character (inverted) logical operator.
procedure, private, pass(lhs) :: string_le_string !< Lower equal than to string logical operator.
procedure, private, pass(lhs) :: string_le_character !< Lower equal than to character logical operator.
procedure, private, pass(rhs) :: character_le_string !< Lower equal than to character (inverted) logical operator.
procedure, private, pass(lhs) :: string_ge_string !< Greater equal than to string logical operator.
procedure, private, pass(lhs) :: string_ge_character !< Greater equal than to character logical operator.
procedure, private, pass(rhs) :: character_ge_string !< Greater equal than to character (inverted) logical operator.
procedure, private, pass(lhs) :: string_gt_string !< Greater than to string logical operator.
procedure, private, pass(lhs) :: string_gt_character !< Greater than to character logical operator.
procedure, private, pass(rhs) :: character_gt_string !< Greater than to character (inverted) logical operator.
! IO
procedure, private, pass(dtv) :: read_formatted !< Formatted input.
procedure, private, pass(dtv) :: read_delimited !< Read a delimited input.
procedure, private, pass(dtv) :: read_undelimited !< Read an undelimited input.
procedure, private, pass(dtv) :: read_undelimited_listdirected !< Read an undelimited list directed input.
procedure, private, pass(dtv) :: write_formatted !< Formatted output.
procedure, private, pass(dtv) :: read_unformatted !< Unformatted input.
procedure, private, pass(dtv) :: write_unformatted !< Unformatted output.
! miscellanea
procedure, private, pass(self) :: replace_one_occurrence !< Replace the first occurrence of substring old by new.
endtype string