-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_utility.f90
More file actions
53 lines (43 loc) · 1.51 KB
/
string_utility.f90
File metadata and controls
53 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
!
! String utility module
!
! This module contains helper functions that don't exist in the standard
! set of Fortran intrinsics.
!
module string_utility
! Set defaults for module
implicit none
private
! Declare the public functions exposed by this module
public :: ucase
public :: lcase
! Helper strings to aid in the converstion of upper to lower and
! vice-versa
character (len=*), private, parameter :: LOWER_CASE = &
'abcdefghijklmnopqrstuvwxyz'
character (len=*), private, parameter :: UPPER_CASE = &
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
contains
! Convert string to all uppercase
pure function ucase(Input_String) result(Output_String)
character (len=*), intent (in) :: Input_String
character (len(Input_String)) :: Output_String
integer :: i,n
Output_String = Input_String
do i=1, len(Output_String)
n = index(LOWER_CASE, Output_String(i:i))
if (n /= 0) Output_String(i:i) = UPPER_CASE(n:n)
end do
end function ucase
! Convert string to all lowercase
pure function lcase(Input_String) result(Output_String)
character (len=*), intent (in) :: Input_String
character (len(Input_String)) :: Output_String
integer :: i,n
Output_String = Input_String
do i=1, len(Output_String)
n = index(UPPER_CASE, Output_String(i:i))
if (n /= 0) Output_String(i:i) = LOWER_CASE(n:n)
end do
end function lcase
end module string_utility