Skip to content

faster to_lower and to_upper #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 13, 2023
Merged
Changes from 2 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
12 changes: 6 additions & 6 deletions src/stdlib_ascii.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ 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, la=65, lz= 90
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>=la.and.k<=lz) k = k + wp
if (k>=BA.and.k<=BZ) k = k + wp
t = char(k)

end function char_to_lower
Expand All @@ -237,11 +237,11 @@ contains
pure function char_to_upper(c) result(t)
character(len=1), intent(in) :: c !! A character.
character(len=1) :: t
integer, parameter :: wp= 32, BA=97, BZ= 122
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>=BA.and.k<=BZ) k = k - wp
if (k>=la.and.k<=lz) k = k - wp
t = char(k)

end function char_to_upper
Expand Down