mirror of https://github.com/rwf2/Rocket.git
Replace manual ASCII checks with 'std::char' calls.
This commit is contained in:
parent
83925bbae1
commit
86d0bdddb2
|
@ -64,7 +64,7 @@ fn port_from<'a>(input: &mut RawInput<'a>, bytes: &IndexedBytes<'a>) -> Result<'
|
||||||
let source = Some(input.cow_source());
|
let source = Some(input.cow_source());
|
||||||
let string = bytes.from_cow_source(&source);
|
let string = bytes.from_cow_source(&source);
|
||||||
for (&b, i) in string.iter().rev().zip(&[1, 10, 100, 1000, 10000]) {
|
for (&b, i) in string.iter().rev().zip(&[1, 10, 100, 1000, 10000]) {
|
||||||
if b < b'0' || b > b'9' {
|
if !b.is_ascii_digit() {
|
||||||
return Err(pear_error!("port byte is out of range"));
|
return Err(pear_error!("port byte is out of range"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ fn port_from<'a>(input: &mut RawInput<'a>, bytes: &IndexedBytes<'a>) -> Result<'
|
||||||
|
|
||||||
#[parser]
|
#[parser]
|
||||||
fn port<'a>(input: &mut RawInput<'a>) -> Result<'a, u16> {
|
fn port<'a>(input: &mut RawInput<'a>) -> Result<'a, u16> {
|
||||||
let port_str = take_n_while(5, |c| c >= b'0' && c <= b'9')?;
|
let port_str = take_n_while(5, |c| c.is_ascii_digit())?;
|
||||||
port_from(&port_str)?
|
port_from(&port_str)?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,18 +63,15 @@ pub type SResult<'a, P> = Result<RouteSegment<'a, P>, (&'a str, Error<'a>)>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_ident_start(c: char) -> bool {
|
fn is_ident_start(c: char) -> bool {
|
||||||
('a' <= c && c <= 'z')
|
c.is_ascii_alphabetic()
|
||||||
|| ('A' <= c && c <= 'Z')
|
|
||||||
|| c == '_'
|
|| c == '_'
|
||||||
|| (c > '\x7f' && UnicodeXID::is_xid_start(c))
|
|| (c > '\x7f' && UnicodeXID::is_xid_start(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_ident_continue(c: char) -> bool {
|
fn is_ident_continue(c: char) -> bool {
|
||||||
('a' <= c && c <= 'z')
|
c.is_ascii_alphanumeric()
|
||||||
|| ('A' <= c && c <= 'Z')
|
|
||||||
|| c == '_'
|
|| c == '_'
|
||||||
|| ('0' <= c && c <= '9')
|
|
||||||
|| (c > '\x7f' && UnicodeXID::is_xid_continue(c))
|
|| (c > '\x7f' && UnicodeXID::is_xid_continue(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,7 @@ fn is_not_separator(byte: char) -> bool {
|
||||||
// FIXME: Be more permissive here?
|
// FIXME: Be more permissive here?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_ident_char(byte: char) -> bool {
|
fn is_ident_char(byte: char) -> bool {
|
||||||
match byte {
|
byte.is_ascii_alphanumeric() || byte == '_' || byte == '-'
|
||||||
'0'..='9' | 'A'..='Z' | 'a'..='z' | '_' | '-' => true,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[parser]
|
#[parser]
|
||||||
|
|
|
@ -154,7 +154,7 @@ use crate::http::{RawStr, uri::{Segments, SegmentError}};
|
||||||
/// _ => return Err(param)
|
/// _ => return Err(param)
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// if !key.chars().all(|c| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
/// if !key.chars().all(|c| c.is_ascii_alphabetic()) {
|
||||||
/// return Err(param);
|
/// return Err(param);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
|
|
@ -35,11 +35,7 @@ impl<'a> fmt::Display for PasteID<'a> {
|
||||||
|
|
||||||
/// Returns `true` if `id` is a valid paste ID and `false` otherwise.
|
/// Returns `true` if `id` is a valid paste ID and `false` otherwise.
|
||||||
fn valid_id(id: &str) -> bool {
|
fn valid_id(id: &str) -> bool {
|
||||||
id.chars().all(|c| {
|
id.chars().all(|c| c.is_ascii_alphanumeric())
|
||||||
(c >= 'a' && c <= 'z')
|
|
||||||
|| (c >= 'A' && c <= 'Z')
|
|
||||||
|| (c >= '0' && c <= '9')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an instance of `PasteID` if the path segment is a valid ID.
|
/// Returns an instance of `PasteID` if the path segment is a valid ID.
|
||||||
|
|
Loading…
Reference in New Issue