Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/stdlib_ascii.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,27 @@ contains
pure function char_to_lower(c) result(t)
character(len=1), intent(in) :: c !! A character.
character(len=1) :: t
integer, parameter :: wp= 32, BA=iachar('A'), BZ=iachar('Z')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do the same for wp:

Suggested change
integer, parameter :: wp= 32, BA=iachar('A'), BZ=iachar('Z')
integer, parameter :: wp= iachar('A')-iachar('a'), BA=iachar('A'), BZ=iachar('Z')

Or is it not correct?

integer :: k
!Check whether the integer equivalent is between BA=65 and BZ=90
k = ichar(c)
if (k>=BA.and.k<=BZ) k = k + wp
t = char(k)

k = index( uppercase, c )

if ( k > 0 ) then
t = lowercase(k:k)
else
t = c
endif
end function char_to_lower

!> Returns the corresponding uppercase letter, if `c` is a lowercase
!> ASCII character, otherwise `c` itself.
pure function char_to_upper(c) result(t)
character(len=1), intent(in) :: c !! A character.
character(len=1) :: t
integer, parameter :: wp= 32, la=iachar('a'), lz=iachar('z')
integer :: k
!Check whether the integer equivalent is between la=97 and lz=122
k = ichar(c)
if (k>=la.and.k<=lz) k = k - wp
t = char(k)

k = index( lowercase, c )

if ( k > 0 ) then
t = uppercase(k:k)
else
t = c
endif
end function char_to_upper

!> Convert character variable to lower case
Expand Down