From 975d38a75a39b32149ac84d6b540e074b110d9ae Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 9 Jun 2022 08:50:25 +0900 Subject: [PATCH] Replace ad-hoc eq_ignore_ascii_case with slice::eq_ignore_ascii_case The latter has been available since rust 1.23.0. --- src/lib.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 22c1afc39..fa334fe54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -538,32 +538,13 @@ fn ok_or(t: Option, e: E) -> Result { } } -// Reimplemented here because std::ascii is not available in libcore -fn eq_ignore_ascii_case(a: &str, b: &str) -> bool { - fn to_ascii_uppercase(c: u8) -> u8 { - if c >= b'a' && c <= b'z' { - c - b'a' + b'A' - } else { - c - } - } - - if a.len() == b.len() { - a.bytes() - .zip(b.bytes()) - .all(|(a, b)| to_ascii_uppercase(a) == to_ascii_uppercase(b)) - } else { - false - } -} - impl FromStr for Level { type Err = ParseLevelError; fn from_str(level: &str) -> Result { ok_or( LOG_LEVEL_NAMES .iter() - .position(|&name| eq_ignore_ascii_case(name, level)) + .position(|&name| name.eq_ignore_ascii_case(level)) .into_iter() .filter(|&idx| idx != 0) .map(|idx| Level::from_usize(idx).unwrap()) @@ -744,7 +725,7 @@ impl FromStr for LevelFilter { ok_or( LOG_LEVEL_NAMES .iter() - .position(|&name| eq_ignore_ascii_case(name, level)) + .position(|&name| name.eq_ignore_ascii_case(level)) .map(|p| LevelFilter::from_usize(p).unwrap()), ParseLevelError(()), )