Skip to content

Commit 86d0bdd

Browse files
gcarqSergioBenitez
authored andcommitted
Replace manual ASCII checks with 'std::char' calls.
1 parent 83925bb commit 86d0bdd

File tree

5 files changed

+7
-17
lines changed

5 files changed

+7
-17
lines changed

core/http/src/parse/uri/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn port_from<'a>(input: &mut RawInput<'a>, bytes: &IndexedBytes<'a>) -> Result<'
6464
let source = Some(input.cow_source());
6565
let string = bytes.from_cow_source(&source);
6666
for (&b, i) in string.iter().rev().zip(&[1, 10, 100, 1000, 10000]) {
67-
if b < b'0' || b > b'9' {
67+
if !b.is_ascii_digit() {
6868
return Err(pear_error!("port byte is out of range"));
6969
}
7070

@@ -80,7 +80,7 @@ fn port_from<'a>(input: &mut RawInput<'a>, bytes: &IndexedBytes<'a>) -> Result<'
8080

8181
#[parser]
8282
fn port<'a>(input: &mut RawInput<'a>) -> Result<'a, u16> {
83-
let port_str = take_n_while(5, |c| c >= b'0' && c <= b'9')?;
83+
let port_str = take_n_while(5, |c| c.is_ascii_digit())?;
8484
port_from(&port_str)?
8585
}
8686

core/http/src/route.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,15 @@ pub type SResult<'a, P> = Result<RouteSegment<'a, P>, (&'a str, Error<'a>)>;
6363

6464
#[inline]
6565
fn is_ident_start(c: char) -> bool {
66-
('a' <= c && c <= 'z')
67-
|| ('A' <= c && c <= 'Z')
66+
c.is_ascii_alphabetic()
6867
|| c == '_'
6968
|| (c > '\x7f' && UnicodeXID::is_xid_start(c))
7069
}
7170

7271
#[inline]
7372
fn is_ident_continue(c: char) -> bool {
74-
('a' <= c && c <= 'z')
75-
|| ('A' <= c && c <= 'Z')
73+
c.is_ascii_alphanumeric()
7674
|| c == '_'
77-
|| ('0' <= c && c <= '9')
7875
|| (c > '\x7f' && UnicodeXID::is_xid_continue(c))
7976
}
8077

core/lib/src/config/toml_ext.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ fn is_not_separator(byte: char) -> bool {
2323
// FIXME: Be more permissive here?
2424
#[inline(always)]
2525
fn is_ident_char(byte: char) -> bool {
26-
match byte {
27-
'0'..='9' | 'A'..='Z' | 'a'..='z' | '_' | '-' => true,
28-
_ => false
29-
}
26+
byte.is_ascii_alphanumeric() || byte == '_' || byte == '-'
3027
}
3128

3229
#[parser]

core/lib/src/request/param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ use crate::http::{RawStr, uri::{Segments, SegmentError}};
154154
/// _ => return Err(param)
155155
/// };
156156
///
157-
/// if !key.chars().all(|c| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
157+
/// if !key.chars().all(|c| c.is_ascii_alphabetic()) {
158158
/// return Err(param);
159159
/// }
160160
///

examples/pastebin/src/paste_id.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ impl<'a> fmt::Display for PasteID<'a> {
3535

3636
/// Returns `true` if `id` is a valid paste ID and `false` otherwise.
3737
fn valid_id(id: &str) -> bool {
38-
id.chars().all(|c| {
39-
(c >= 'a' && c <= 'z')
40-
|| (c >= 'A' && c <= 'Z')
41-
|| (c >= '0' && c <= '9')
42-
})
38+
id.chars().all(|c| c.is_ascii_alphanumeric())
4339
}
4440

4541
/// Returns an instance of `PasteID` if the path segment is a valid ID.

0 commit comments

Comments
 (0)