This commit is contained in:
Nikolay Kim 2020-12-22 19:55:06 +06:00
parent 3cdfdadeba
commit 1e2bc4a9e2
15 changed files with 66 additions and 94 deletions

View file

@ -50,11 +50,11 @@ pub(super) fn requote(val: &[u8]) -> Option<String> {
#[inline]
fn from_hex(v: u8) -> Option<u8> {
if v >= b'0' && v <= b'9' {
if (b'0'..=b'9').contains(&v) {
Some(v - 0x30) // ord('0') == 0x30
} else if v >= b'A' && v <= b'F' {
} else if (b'A'..=b'F').contains(&v) {
Some(v - 0x41 + 10) // ord('A') == 0x41
} else if v >= b'a' && v <= b'f' {
} else if (b'a'..=b'f').contains(&v) {
Some(v - 0x61 + 10) // ord('a') == 0x61
} else {
None

View file

@ -32,17 +32,16 @@ enum PathElement {
impl PathElement {
fn is_str(&self) -> bool {
match self {
PathElement::Str(_) => true,
_ => false,
}
matches!(self, PathElement::Str(_))
}
fn into_str(self) -> String {
match self {
PathElement::Str(s) => s,
_ => panic!(),
}
}
fn as_str(&self) -> &str {
match self {
PathElement::Str(s) => s.as_str(),
@ -380,10 +379,8 @@ impl ResourceDef {
}
if !pattern.is_empty() {
// handle tail expression for static segment
if pattern.ends_with('*') {
let pattern =
Regex::new(&format!("^{}(.+)", &pattern[..pattern.len() - 1]))
.unwrap();
if let Some(stripped) = pattern.strip_suffix('*') {
let pattern = Regex::new(&format!("^{}(.+)", stripped)).unwrap();
pelems.push(Segment::Dynamic {
pattern,
names: Vec::new(),

View file

@ -244,8 +244,8 @@ impl Tree {
}
}
let path = if path.starts_with('/') {
&path[1..]
let path = if let Some(path) = path.strip_prefix('/') {
path
} else {
base_skip -= 1;
path
@ -282,8 +282,8 @@ impl Tree {
return None;
}
let path = if path.starts_with('/') {
&path[1..]
let path = if let Some(path) = path.strip_prefix('/') {
path
} else {
base_skip -= 1;
path
@ -356,11 +356,8 @@ impl Tree {
path.len()
};
let segment = T::unquote(&path[..idx]);
let quoted = if let Cow::Owned(_) = segment {
true
} else {
false
};
let quoted = matches!(segment, Cow::Owned(_));
// check segment match
let is_match = match key[0] {
Segment::Static(ref pattern) => {