Skip to content

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

Open
@arjenmarkus

Description

@arjenmarkus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    implementationImplementation in experimental and submission of a PRtopic: stringsString processing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions