Skip to content

Commit

Permalink
Update librustc_unicode/tables.rs
Browse files Browse the repository at this point in the history
with a new version generated by src/etc/unicode.py.
  • Loading branch information
ranma42 committed Jan 4, 2016
1 parent aa77f39 commit 3fff634
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/librustc_unicode/tables.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<usize> {
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])] = &[
Expand Down

0 comments on commit 3fff634

Please sign in to comment.