FUTILS
Some basic Fortran Utilities
Loading...
Searching...
No Matches
strings_m Module Reference

Data Types

interface  assignment(=)
interface  index
interface  operator(//)
interface  operator(/=)
interface  operator(==)
interface  string_t
type  string_tools_t

Functions/Subroutines

pure type(string_t) function create_string (s)
pure logical function equiv_character_string (lhs, rhs)
pure logical function equiv_string_character (lhs, rhs)
pure logical function equiv_string_string (lhs, rhs)
pure logical function nequiv_character_string (lhs, rhs)
pure logical function nequiv_string_character (lhs, rhs)
pure logical function nequiv_string_string (lhs, rhs)
pure character(len=:) function, allocatable concat_character_and_string (lhs, rhs)
pure character(len=:) function, allocatable concat_string_and_character (lhs, rhs)
pure character(len=:) function, allocatable concat_string_and_string (lhs, rhs)
subroutine write_string (str, unit, iotype, v_list, iostat, iomsg)
subroutine write_string_unformatted (str, unit, iostat, iomsg)
subroutine read_string (str, unit, iotype, v_list, iostat, iomsg)
pure subroutine assign_int4_to_string (outstring, inint)
pure subroutine assign_character_to_string (outstring, inchar)
pure subroutine assign_string_to_string (outstring, instring)
pure type(string_t) function make_sentence_from_array_of_strings (array)
subroutine make_upper (self)
subroutine make_lower (self)
pure integer function string_index (self, s)
pure subroutine remove (self, s)

Variables

character *26, parameter, private upper_case ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
character *26, parameter, private lower_case ="abcdefghijklmnopqrstuvwxyz"
type(string_tools_t), parameter, public string_tools = string_tools_t()

Function/Subroutine Documentation

◆ assign_character_to_string()

pure subroutine strings_m::assign_character_to_string ( type(string_t), intent(inout) outstring,
character(len=*), intent(in) inchar )

Definition at line 225 of file strings.f90.

226 implicit none
227 type(string_t), intent(inout) :: outstring
228 character(len=*), intent(in) :: inchar
229 character(len=:), allocatable :: tempchar
230
231 !Note: outstring is intent(inout) and we are making a copy of inchar below to account for
232 !Edge cases like string = string%s(1:5)
233 allocate(character(len(inchar)) :: tempchar)
234 tempchar = inchar
235
236 if(allocated(outstring%s)) deallocate(outstring%s)
237 allocate(character(len(tempchar)) :: outstring%s)
238 outstring%s = tempchar
239 outstring%len = len(outstring%s)
240

◆ assign_int4_to_string()

pure subroutine strings_m::assign_int4_to_string ( type(string_t), intent(out) outstring,
integer*4, intent(in) inint )

Definition at line 210 of file strings.f90.

211 implicit none
212 type(string_t), intent(out) :: outstring
213 integer*4, intent(in) :: inint
214 character(len=512) :: tempchar
215 integer :: len
216
217 if(allocated(outstring%s)) deallocate(outstring%s)
218 write(tempchar,'(I0)') inint
219 len = len_trim(tempchar)
220 allocate(character(len) :: outstring%s)
221 outstring%s = trim(adjustl(tempchar))
222

◆ assign_string_to_string()

pure subroutine strings_m::assign_string_to_string ( type(string_t), intent(out) outstring,
type(string_t), intent(in) instring )

Definition at line 243 of file strings.f90.

244 implicit none
245 type(string_t), intent(out) :: outstring
246 type(string_t), intent(in) :: instring
247
248 if(allocated(outstring%s)) deallocate(outstring%s)
249 allocate(character(instring%len) :: outstring%s)
250 outstring%s = instring%s
251 outstring%len = instring%len

◆ concat_character_and_string()

pure character(len=:) function, allocatable strings_m::concat_character_and_string ( character(len=*), intent(in) lhs,
type(string_t), intent(in) rhs )

Definition at line 144 of file strings.f90.

145 implicit none
146 character(len=*), intent(in) :: lhs
147 type(string_t), intent(in) :: rhs
148 character(len=:), allocatable :: retval
149
150 allocate(character(len(lhs)+rhs%len) :: retval)
151 retval = lhs//rhs%s
152

◆ concat_string_and_character()

pure character(len=:) function, allocatable strings_m::concat_string_and_character ( type(string_t), intent(in) lhs,
character(len=*), intent(in) rhs )

Definition at line 155 of file strings.f90.

156 implicit none
157 type(string_t), intent(in) :: lhs
158 character(len=*), intent(in) :: rhs
159 character(len=:), allocatable :: retval
160
161 allocate(character(len(rhs)+lhs%len) :: retval)
162 retval = lhs%s//rhs
163

◆ concat_string_and_string()

pure character(len=:) function, allocatable strings_m::concat_string_and_string ( type(string_t), intent(in) lhs,
type(string_t), intent(in) rhs )

Definition at line 166 of file strings.f90.

167 implicit none
168 type(string_t), intent(in) :: lhs, rhs
169 character(len=:), allocatable :: retval
170
171 allocate(character(lhs%len+rhs%len) :: retval)
172 retval = lhs%s//rhs%s
173

◆ create_string()

pure type(string_t) function strings_m::create_string ( character(len=*), intent(in) s)

Definition at line 84 of file strings.f90.

85 implicit none
86 character(len=*), intent(in) :: s
87
88 res = s

◆ equiv_character_string()

pure logical function strings_m::equiv_character_string ( character(len=*), intent(in) lhs,
type(string_t), intent(in) rhs )

Definition at line 91 of file strings.f90.

92 implicit none
93 character(len=*), intent(in) :: lhs
94 type(string_t), intent(in) :: rhs
95
96 retval = (lhs == rhs%s)
97

◆ equiv_string_character()

pure logical function strings_m::equiv_string_character ( type(string_t), intent(in) lhs,
character(len=*), intent(in) rhs )

Definition at line 100 of file strings.f90.

101 implicit none
102 type(string_t), intent(in) :: lhs
103 character(len=*), intent(in) :: rhs
104
105 retval = (lhs%s == rhs)
106

◆ equiv_string_string()

pure logical function strings_m::equiv_string_string ( type(string_t), intent(in) lhs,
type(string_t), intent(in) rhs )

Definition at line 109 of file strings.f90.

110 implicit none
111 type(string_t), intent(in) :: lhs, rhs
112
113 retval = (lhs%s == rhs%s)
114

◆ make_lower()

subroutine strings_m::make_lower ( class(string_t), intent(inout) self)

Definition at line 282 of file strings.f90.

283 implicit none
284 class(string_t), intent(inout) :: self
285 integer :: i, k
286
287 do i=1, len(self%s)
288 k = index(upper_case,self%s(i:i))
289 if(k /= 0) self%s(i:i) = lower_case(k:k)
290 enddo
291

References lower_case, and upper_case.

◆ make_sentence_from_array_of_strings()

pure type(string_t) function strings_m::make_sentence_from_array_of_strings ( type(string_t), dimension(:), intent(in) array)

Definition at line 254 of file strings.f90.

255 implicit none
256 type(string_t), dimension(:), intent(in) :: array
257 type(string_t) :: s
258
259 integer :: n, i
260
261 n = size(array)
262
263 s = array(1)
264 do i=2, n
265 s = s // ' ' // array(i)
266 enddo
267

◆ make_upper()

subroutine strings_m::make_upper ( class(string_t), intent(inout) self)

Definition at line 270 of file strings.f90.

271 implicit none
272 class(string_t), intent(inout) :: self
273 integer :: i, k
274
275 do i=1, len(self%s)
276 k = index(lower_case,self%s(i:i))
277 if(k /= 0) self%s(i:i) = upper_case(k:k)
278 enddo
279

References lower_case, and upper_case.

◆ nequiv_character_string()

pure logical function strings_m::nequiv_character_string ( character(len=*), intent(in) lhs,
type(string_t), intent(in) rhs )

Definition at line 117 of file strings.f90.

118 implicit none
119 character(len=*), intent(in) :: lhs
120 type(string_t), intent(in) :: rhs
121
122 retval = (lhs /= rhs%s)
123

◆ nequiv_string_character()

pure logical function strings_m::nequiv_string_character ( type(string_t), intent(in) lhs,
character(len=*), intent(in) rhs )

Definition at line 126 of file strings.f90.

127 implicit none
128 type(string_t), intent(in) :: lhs
129 character(len=*), intent(in) :: rhs
130
131 retval = (lhs%s /= rhs)
132

◆ nequiv_string_string()

pure logical function strings_m::nequiv_string_string ( type(string_t), intent(in) lhs,
type(string_t), intent(in) rhs )

Definition at line 135 of file strings.f90.

136 implicit none
137 type(string_t), intent(in) :: lhs, rhs
138
139 retval = (lhs%s /= rhs%s)
140

◆ read_string()

subroutine strings_m::read_string ( class(string_t), intent(inout) str,
integer, intent(in) unit,
character(*), intent(in) iotype,
integer, dimension(:), intent(in) v_list,
integer, intent(out) iostat,
character(*), intent(inout) iomsg )

Definition at line 198 of file strings.f90.

199 class(string_t), INTENT(INOUT) :: str
200 INTEGER, INTENT(IN) :: unit
201 CHARACTER(*), INTENT(IN) :: iotype
202 INTEGER, INTENT(IN) :: v_list(:)
203 INTEGER, INTENT(OUT) :: iostat
204 CHARACTER(*), INTENT(INOUT) :: iomsg
205
206 READ (unit, *, iostat=iostat) str%s
207

◆ remove()

pure subroutine strings_m::remove ( class(string_t), intent(inout) self,
character(len=*), intent(in) s )

Definition at line 302 of file strings.f90.

303 implicit none
304 class(string_t), intent(inout) :: self
305 character(len=*), intent(in) :: s
306
307 integer :: i, j
308
309 do i=1, len(s)
310
311 j = index(self%s, s(i:i))
312 do while(j /= 0)
313 self = self%s(1:j-1)//self%s(j+1:)
314
315 j = index(self%s, s(i:i))
316 enddo
317
318 enddo
319
320

◆ string_index()

pure integer function strings_m::string_index ( class(string_t), intent(in) self,
character(len=*), intent(in) s )

Definition at line 294 of file strings.f90.

295 implicit none
296 class(string_t), intent(in) :: self
297 character(len=*), intent(in) :: s
298
299 string_index = index(self%s, s)

Referenced by strings_m::index::string_index().

Here is the caller graph for this function:

◆ write_string()

subroutine strings_m::write_string ( class(string_t), intent(in) str,
integer, intent(in) unit,
character(*), intent(in) iotype,
integer, dimension(:), intent(in) v_list,
integer, intent(out) iostat,
character(*), intent(inout) iomsg )

Definition at line 176 of file strings.f90.

177 class(string_t), intent(in) :: str
178 INTEGER, INTENT(IN) :: unit
179 CHARACTER(*), INTENT(IN) :: iotype
180 INTEGER, INTENT(IN) :: v_list(:)
181 INTEGER, INTENT(OUT) :: iostat
182 CHARACTER(*), INTENT(INOUT) :: iomsg
183
184 write(unit, '(A)' , iostat=iostat) str%s
185

◆ write_string_unformatted()

subroutine strings_m::write_string_unformatted ( class(string_t), intent(in) str,
integer, intent(in) unit,
integer, intent(out) iostat,
character(*), intent(inout) iomsg )

Definition at line 188 of file strings.f90.

189 class(string_t), intent(in) :: str
190 INTEGER, INTENT(IN) :: unit
191 INTEGER, INTENT(OUT) :: iostat
192 CHARACTER(*), INTENT(INOUT) :: iomsg
193
194 write(unit, *, iostat=iostat) str%s
195

Variable Documentation

◆ lower_case

character*26, parameter, private strings_m::lower_case ="abcdefghijklmnopqrstuvwxyz"
private

Definition at line 39 of file strings.f90.

Referenced by make_lower(), and make_upper().

◆ string_tools

type(string_tools_t), parameter, public strings_m::string_tools = string_tools_t()

Definition at line 80 of file strings.f90.

80 type(string_tools_t), public, parameter :: string_tools = string_tools_t()

◆ upper_case

character*26, parameter, private strings_m::upper_case ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
private

Definition at line 39 of file strings.f90.

39 character*26, private, parameter :: &
40 upper_case="ABCDEFGHIJKLMNOPQRSTUVWXYZ", &
41 lower_case="abcdefghijklmnopqrstuvwxyz"

Referenced by make_lower(), and make_upper().