Skip to content

promote other ascii functions to elemental #977

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
167 changes: 166 additions & 1 deletion doc/specs/stdlib_ascii.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,173 @@ intrinsic character variables and constants.

## Constants provided by `stdlib_ascii`

@note Specification of constants is currently incomplete.
### `NUL`

Null character

### `SOH`

Start Of Heading Character

### `STX`

Start Of Text character

### `ETX`

End Of Text character

### `EOT`

End Of Transmission character

### `ENQ`

Enquiry character

### `ACK`

Acknowledge character

### `BEL`

Bell character

### `BS`

Backspace character

### `TAB`

Horizontal Tab character

### `LF`

Line Feed character

### `VT`

Vertical Tab character

### `FF`

Form Feed character

### `CR`

Carriage Return character

### `SO`

Shift Out character

### `SI`

Shift In character

### `DLE`

Data Link Escape character

### `DC1`

Device Control 1 character

### `DC2`

Device Control 2 character

### `DC3`

Device Control 3 character

### `DC4`

Device Control 4 character

### `NAK`

Negative Acknowledge character

### `SYN`

Synchronous Idle character

### `ETB`

End of Transmission Block character

### `CAN`

Cancel character

### `EM`

End of Medium character

### `SUB`

Substitute character

### `ESC`

Escape character

### `FS`

File separator character

### `GS`

Group Separator character

### `RS`

Record Separator character

### `US`

Unit separator character

### `DEL`

Delete character

### `fullhex_digits`

All the hexadecimal digits (0-9, A-F, a-f)

### `hex_digits`

All the numerical and uppercase hexadecimal digits (0-9, A-F)

### `lowerhex_digits`

All the numerical and lowercase hexadecimal digits (0-9, a-f)

### `digits`

base 10 digits (0-9)

### `octal_digits`

base 8 digits (0-7)

### `letters`

Uppercase and lowercase letters of the english alphabet (A-Z, a-z)

### `uppercase`

Uppercase english albhabets (A-Z)

### `lowercase`

Lowercase english albhabets (a-z)

### `whitespace`

All the ascii whitespace characters (space, horizontal tab, vertical tab, carriage return, line feed, form feed)

## Specification of the `stdlib_ascii` procedures

Expand Down
28 changes: 14 additions & 14 deletions src/stdlib_ascii.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -107,47 +107,47 @@ module stdlib_ascii
contains

!> Checks whether `c` is an ASCII letter (A .. Z, a .. z).
pure logical function is_alpha(c)
elemental 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

!> Checks whether `c` is a letter or a number (0 .. 9, a .. z, A .. Z).
pure logical function is_alphanum(c)
elemental logical function is_alphanum(c)
character(len=1), intent(in) :: c !! The character to test.
is_alphanum = (c >= '0' .and. c <= '9') .or. (c >= 'a' .and. c <= 'z') &
.or. (c >= 'A' .and. c <= 'Z')
end function

!> Checks whether or not `c` is in the ASCII character set -
!> i.e. in the range 0 .. 0x7F.
pure logical function is_ascii(c)
elemental logical function is_ascii(c)
character(len=1), intent(in) :: c !! The character to test.
is_ascii = iachar(c) <= int(z'7F')
end function

!> Checks whether `c` is a control character.
pure logical function is_control(c)
elemental logical function is_control(c)
character(len=1), intent(in) :: c !! The character to test.
integer :: ic
ic = iachar(c)
is_control = ic < int(z'20') .or. ic == int(z'7F')
end function

!> Checks whether `c` is a digit (0 .. 9).
pure logical function is_digit(c)
elemental logical function is_digit(c)
character(len=1), intent(in) :: c !! The character to test.
is_digit = ('0' <= c) .and. (c <= '9')
end function

!> Checks whether `c` is a digit in base 8 (0 .. 7).
pure logical function is_octal_digit(c)
elemental logical function is_octal_digit(c)
character(len=1), intent(in) :: c !! The character to test.
is_octal_digit = (c >= '0') .and. (c <= '7');
end function

!> Checks whether `c` is a digit in base 16 (0 .. 9, A .. F, a .. f).
pure logical function is_hex_digit(c)
elemental logical function is_hex_digit(c)
character(len=1), intent(in) :: c !! The character to test.
is_hex_digit = (c >= '0' .and. c <= '9') .or. (c >= 'a' .and. c <= 'f') &
.or. (c >= 'A' .and. c <= 'F')
Expand All @@ -156,7 +156,7 @@ contains
!> Checks whether or not `c` is a punctuation character. That includes
!> all ASCII characters which are not control characters, letters,
!> digits, or whitespace.
pure logical function is_punctuation(c)
elemental logical function is_punctuation(c)
character(len=1), intent(in) :: c !! The character to test.
integer :: ic
ic = iachar(c) ! '~' '!'
Expand All @@ -166,7 +166,7 @@ contains

!> Checks whether or not `c` is a printable character other than the
!> space character.
pure logical function is_graphical(c)
elemental logical function is_graphical(c)
character(len=1), intent(in) :: c !! The character to test.
integer :: ic
ic = iachar(c)
Expand All @@ -177,7 +177,7 @@ contains

!> Checks whether or not `c` is a printable character - including the
!> space character.
pure logical function is_printable(c)
elemental logical function is_printable(c)
character(len=1), intent(in) :: c !! The character to test.
integer :: ic
ic = iachar(c)
Expand All @@ -186,23 +186,23 @@ contains
end function

!> Checks whether `c` is a lowercase ASCII letter (a .. z).
pure logical function is_lower(c)
elemental logical function is_lower(c)
character(len=1), intent(in) :: c !! The character to test.
integer :: ic
ic = iachar(c)
is_lower = ic >= iachar('a') .and. ic <= iachar('z')
end function

!> Checks whether `c` is an uppercase ASCII letter (A .. Z).
pure logical function is_upper(c)
elemental logical function is_upper(c)
character(len=1), intent(in) :: c !! The character to test.
is_upper = (c >= 'A') .and. (c <= 'Z')
end function

!> Checks whether or not `c` is a whitespace character. That includes the
!> space, tab, vertical tab, form feed, carriage return, and linefeed
!> characters.
pure logical function is_white(c)
elemental logical function is_white(c)
character(len=1), intent(in) :: c !! The character to test.
integer :: ic
ic = iachar(c) ! TAB, LF, VT, FF, CR
Expand All @@ -211,7 +211,7 @@ contains

!> Checks whether or not `c` is a blank character. That includes the
!> only the space and tab characters
pure logical function is_blank(c)
elemental logical function is_blank(c)
character(len=1), intent(in) :: c !! The character to test.
integer :: ic
ic = iachar(c) ! TAB
Expand Down
Loading
Loading