|
16 | 16 | /// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
|
17 | 17 | pub const UNICODE_VERSION: (u64, u64, u64) = (8, 0, 0);
|
18 | 18 |
|
19 |
| -fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool { |
| 19 | +fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool { |
20 | 20 | use core::cmp::Ordering::{Equal, Less, Greater};
|
21 |
| - r.binary_search_by(|&(lo,hi)| { |
22 |
| - if lo <= c && c <= hi { Equal } |
23 |
| - else if hi < c { Less } |
24 |
| - else { Greater } |
25 |
| - }).is_ok() |
| 21 | + r.binary_search_by(|&(lo, hi)| { |
| 22 | + if c < lo { |
| 23 | + Greater |
| 24 | + } else if hi < c { |
| 25 | + Less |
| 26 | + } else { |
| 27 | + Equal |
| 28 | + } |
| 29 | + }) |
| 30 | + .is_ok() |
26 | 31 | }
|
27 | 32 |
|
28 | 33 | pub mod general_category {
|
@@ -1188,34 +1193,25 @@ pub mod property {
|
1188 | 1193 | }
|
1189 | 1194 |
|
1190 | 1195 | pub mod conversions {
|
1191 |
| - use core::cmp::Ordering::{Equal, Less, Greater}; |
1192 | 1196 | use core::option::Option;
|
1193 | 1197 | use core::option::Option::{Some, None};
|
1194 |
| - use core::result::Result::{Ok, Err}; |
1195 | 1198 |
|
1196 | 1199 | pub fn to_lower(c: char) -> [char; 3] {
|
1197 | 1200 | match bsearch_case_table(c, to_lowercase_table) {
|
1198 |
| - None => [c, '\0', '\0'], |
1199 |
| - Some(index) => to_lowercase_table[index].1 |
| 1201 | + None => [c, '\0', '\0'], |
| 1202 | + Some(index) => to_lowercase_table[index].1, |
1200 | 1203 | }
|
1201 | 1204 | }
|
1202 | 1205 |
|
1203 | 1206 | pub fn to_upper(c: char) -> [char; 3] {
|
1204 | 1207 | match bsearch_case_table(c, to_uppercase_table) {
|
1205 | 1208 | None => [c, '\0', '\0'],
|
1206 |
| - Some(index) => to_uppercase_table[index].1 |
| 1209 | + Some(index) => to_uppercase_table[index].1, |
1207 | 1210 | }
|
1208 | 1211 | }
|
1209 | 1212 |
|
1210 | 1213 | fn bsearch_case_table(c: char, table: &'static [(char, [char; 3])]) -> Option<usize> {
|
1211 |
| - match table.binary_search_by(|&(key, _)| { |
1212 |
| - if c == key { Equal } |
1213 |
| - else if key < c { Less } |
1214 |
| - else { Greater } |
1215 |
| - }) { |
1216 |
| - Ok(i) => Some(i), |
1217 |
| - Err(_) => None, |
1218 |
| - } |
| 1214 | + table.binary_search_by(|&(key, _)| key.cmp(&c)).ok() |
1219 | 1215 | }
|
1220 | 1216 |
|
1221 | 1217 | const to_lowercase_table: &'static [(char, [char; 3])] = &[
|
|
0 commit comments