fortran-lang / stdlib

Fortran Standard Library
https://stdlib.fortran-lang.org
MIT License
1.09k stars 169 forks source link

Wrt stdlib_ascii.f90: use iachar/achar consistently #232

Open arjenmarkus opened 4 years ago

arjenmarkus commented 4 years ago

While having a quick look at the documentation, I stumbled upon the implementation of the ASCII functions. For instance:

pure logical function is_alpha(c) character(len=1), intent(in) :: c !! The character to test. is_alpha = (c >= 'A' .and. c <= 'Z') .or. (c >= 'a' .and. c <= 'z') end function

The implementation assumes that the character that is passed is in ASCII encoding. While ubiquitous nowadays, it is certainly not the only possible encoding. For stdlib we should be as general as possible, Here is a possible alternative for the is_alpha() function:

pure logical function is_alpha(cin)
    character(len=1), intent(in) :: cin !! The character to test.
    integer :: c
    c = iachar(cin)
    is_alpha = (c >= iachar('A') .and. c <= iachar('Z')) .or. (c >= iachar('a') .and. c <= iachar('z'))
end function
arjenmarkus commented 4 years ago

Perhaps it is over cautious, but it cannot hurt to consider this.

certik commented 4 years ago

Can you send this as a Pull Request (PR)? I think this change is fine.

arjenmarkus commented 4 years ago

It is not quite complete yet . Will check the rest later.

Op ma 14 sep. 2020 16:07 schreef Ondřej Čertík notifications@github.com:

Can you send this as a Pull Request (PR)? I think this change is fine.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fortran-lang/stdlib/issues/232#issuecomment-692075731, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN6YR2NO6AXASUXBXKEVODSFYPQLANCNFSM4RLQC7FQ .

arjenmarkus commented 4 years ago

Oh dear, I inadvertently pushed it to the central repository instead of creating a pull request. Please have a look at my changes - if not appropriate, I will revert this.

Op di 15 sep. 2020 om 08:06 schreef Arjen Markus <arjen.markus895@gmail.com

:

It is not quite complete yet . Will check the rest later.

Op ma 14 sep. 2020 16:07 schreef Ondřej Čertík notifications@github.com:

Can you send this as a Pull Request (PR)? I think this change is fine.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fortran-lang/stdlib/issues/232#issuecomment-692075731, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN6YR2NO6AXASUXBXKEVODSFYPQLANCNFSM4RLQC7FQ .

14NGiestas commented 4 years ago

I think you should revert the commit so we can fully review the changes, if I'm not mistaken, there is already a missing line in your changes.

arjenmarkus commented 4 years ago

Okay, will do so.

Op wo 16 sep. 2020 17:26 schreef Ian Giestas Pauli <notifications@github.com

:

I think you should revert the commit so we can fully review the changes, if I'm not mistaken, there is already a missing line in your changes.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fortran-lang/stdlib/issues/232#issuecomment-693481091, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN6YR6VUF2ASUV3RASPHW3SGDKJ3ANCNFSM4RLQC7FQ .