From 3fff63400b3032f64cdd3d0743d9a9c2cab019b4 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Mon, 4 Jan 2016 17:49:16 +0100 Subject: [PATCH] Update librustc_unicode/tables.rs with a new version generated by src/etc/unicode.py. --- src/librustc_unicode/tables.rs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/librustc_unicode/tables.rs b/src/librustc_unicode/tables.rs index cf75cf5257714..a147bea791c47 100644 --- a/src/librustc_unicode/tables.rs +++ b/src/librustc_unicode/tables.rs @@ -16,13 +16,18 @@ /// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on. pub const UNICODE_VERSION: (u64, u64, u64) = (8, 0, 0); -fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool { +fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool { use core::cmp::Ordering::{Equal, Less, Greater}; - r.binary_search_by(|&(lo,hi)| { - if lo <= c && c <= hi { Equal } - else if hi < c { Less } - else { Greater } - }).is_ok() + r.binary_search_by(|&(lo, hi)| { + if c < lo { + Greater + } else if hi < c { + Less + } else { + Equal + } + }) + .is_ok() } pub mod general_category { @@ -1188,34 +1193,25 @@ pub mod property { } pub mod conversions { - use core::cmp::Ordering::{Equal, Less, Greater}; use core::option::Option; use core::option::Option::{Some, None}; - use core::result::Result::{Ok, Err}; pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { - None => [c, '\0', '\0'], - Some(index) => to_lowercase_table[index].1 + None => [c, '\0', '\0'], + Some(index) => to_lowercase_table[index].1, } } pub fn to_upper(c: char) -> [char; 3] { match bsearch_case_table(c, to_uppercase_table) { None => [c, '\0', '\0'], - Some(index) => to_uppercase_table[index].1 + Some(index) => to_uppercase_table[index].1, } } fn bsearch_case_table(c: char, table: &'static [(char, [char; 3])]) -> Option { - match table.binary_search_by(|&(key, _)| { - if c == key { Equal } - else if key < c { Less } - else { Greater } - }) { - Ok(i) => Some(i), - Err(_) => None, - } + table.binary_search_by(|&(key, _)| key.cmp(&c)).ok() } const to_lowercase_table: &'static [(char, [char; 3])] = &[