@@ -65,14 +65,18 @@ module stdlib_ascii
65
65
! > Checks whether `c` is an ASCII letter (A .. Z, a .. z).
66
66
pure logical function is_alpha(c)
67
67
character (len= 1 ), intent (in ) :: c ! ! The character to test.
68
- is_alpha = (c >= ' A' .and. c <= ' Z' ) .or. (c >= ' a' .and. c <= ' z' )
68
+ integer :: ic
69
+ ic = iachar (c)
70
+ is_alpha = (ic >= iachar (' A' ) .and. ic <= iachar (' Z' )) .or. (ic >= iachar (' a' ) .and. ic <= iachar (' z' ))
69
71
end function
70
72
71
73
! > Checks whether `c` is a letter or a number (0 .. 9, a .. z, A .. Z).
72
74
pure logical function is_alphanum(c)
73
75
character (len= 1 ), intent (in ) :: c ! ! The character to test.
74
- is_alphanum = (c >= ' 0' .and. c <= ' 9' ) .or. (c >= ' a' .and. c <= ' z' ) &
75
- .or. (c >= ' A' .and. c <= ' Z' )
76
+ integer :: ic
77
+ ic = iachar (c)
78
+ is_alphanum = (ic >= iachar (' 0' ) .and. ic <= iachar (' 9' )) .or. (ic >= iachar (' a' ) .and. ic <= iachar (' z' )) &
79
+ .or. (ic >= iachar (' A' ) .and. ic <= iachar (' Z' ))
76
80
end function
77
81
78
82
! > Checks whether or not `c` is in the ASCII character set -
@@ -93,20 +97,25 @@ pure logical function is_control(c)
93
97
! > Checks whether `c` is a digit (0 .. 9).
94
98
pure logical function is_digit(c)
95
99
character (len= 1 ), intent (in ) :: c ! ! The character to test.
96
- is_digit = (' 0' <= c) .and. (c <= ' 9' )
100
+ integer :: ic
101
+ is_digit = (iachar (' 0' ) <= ic) .and. (ic <= iachar (' 9' ))
97
102
end function
98
103
99
104
! > Checks whether `c` is a digit in base 8 (0 .. 7).
100
105
pure logical function is_octal_digit(c)
101
106
character (len= 1 ), intent (in ) :: c ! ! The character to test.
102
- is_octal_digit = (c >= ' 0' ) .and. (c <= ' 7' );
107
+ integer :: ic
108
+ ic = iachar (c)
109
+ is_octal_digit = (ic >= iachar (' 0' )) .and. (ic <= iachar (' 7' ))
103
110
end function
104
111
105
112
! > Checks whether `c` is a digit in base 16 (0 .. 9, A .. F, a .. f).
106
- pure logical function is_hex_digit(c )
113
+ pure logical function is_hex_digit(cin )
107
114
character (len= 1 ), intent (in ) :: c ! ! The character to test.
108
- is_hex_digit = (c >= ' 0' .and. c <= ' 9' ) .or. (c >= ' a' .and. c <= ' f' ) &
109
- .or. (c >= ' A' .and. c <= ' F' )
115
+ integer :: ic
116
+ ic = iachar (c)
117
+ is_hex_digit = (ic >= iachar (' 0' ) .and. ic <= iachar (' 9' )) .or. (ic >= iachar (' a' ) .and. ic <= iachar (' f' )) &
118
+ .or. (ic >= iachar (' A' ) .and. ic <= iachar (' F' )) .or. (ic >= iachar (' a' ) .and. ic <= iachar (' f' ))
110
119
end function
111
120
112
121
! > Checks whether or not `c` is a punctuation character. That includes
@@ -139,15 +148,17 @@ pure logical function is_printable(c)
139
148
end function
140
149
141
150
! > Checks whether `c` is a lowercase ASCII letter (a .. z).
142
- pure logical function is_lower(c )
151
+ pure logical function is_lower(cin )
143
152
character (len= 1 ), intent (in ) :: c ! ! The character to test.
144
153
is_lower = (c >= ' a' ) .and. (c <= ' z' )
145
154
end function
146
155
147
156
! > Checks whether `c` is an uppercase ASCII letter (A .. Z).
148
157
pure logical function is_upper(c)
149
158
character (len= 1 ), intent (in ) :: c ! ! The character to test.
150
- is_upper = (c >= ' A' ) .and. (c <= ' Z' )
159
+ integer :: ic
160
+ ic = iachar (c)
161
+ is_upper = (ic >= iachar (' A' )) .and. (ic <= iachar (' Z' ))
151
162
end function
152
163
153
164
! > Checks whether or not `c` is a whitespace character. That includes the
@@ -157,7 +168,7 @@ pure logical function is_white(c)
157
168
character (len= 1 ), intent (in ) :: c ! ! The character to test.
158
169
integer :: ic
159
170
ic = iachar (c) ! TAB, LF, VT, FF, CR
160
- is_white = (c == ' ' ) .or. (ic >= int (z' 09' ) .and. ic <= int (z' 0D' ));
171
+ is_white = (ic == iachar ( ' ' ) ) .or. (ic >= int (z' 09' ) .and. ic <= int (z' 0D' ));
161
172
end function
162
173
163
174
! > Checks whether or not `c` is a blank character. That includes the
@@ -166,7 +177,7 @@ pure logical function is_blank(c)
166
177
character (len= 1 ), intent (in ) :: c ! ! The character to test.
167
178
integer :: ic
168
179
ic = iachar (c) ! TAB
169
- is_blank = (c == ' ' ) .or. (ic == int (z' 09' ));
180
+ is_blank = (ic == iachar ( ' ' ) ) .or. (ic == int (z' 09' ));
170
181
end function
171
182
172
183
! > Returns the corresponding lowercase letter, if `c` is an uppercase
0 commit comments