// Copyright 2015 The Servo Project Developers. See the // COPYRIGHT file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
//! Accessor for `Bidi_Class` property from Unicode Character Database (UCD)
mod tables;
pubuseself::tables::{BidiClass, UNICODE_VERSION}; #[cfg(feature = "hardcoded-data")] use core::char; #[cfg(feature = "hardcoded-data")] use core::cmp::Ordering::{Equal, Greater, Less};
#[cfg(feature = "hardcoded-data")] useself::tables::bidi_class_table; usecrate::data_source::BidiMatchedOpeningBracket; usecrate::BidiClass::*; #[cfg(feature = "hardcoded-data")] usecrate::BidiDataSource; /// Hardcoded Bidi data that ships with the unicode-bidi crate. /// /// This can be enabled with the default `hardcoded-data` Cargo feature. #[cfg(feature = "hardcoded-data")] pubstruct HardcodedBidiData;
/// Find the `BidiClass` of a single char. #[cfg(feature = "hardcoded-data")] pubfn bidi_class(c: char) -> BidiClass {
bsearch_range_value_table(c, bidi_class_table)
}
/// If this character is a bracket according to BidiBrackets.txt, /// return the corresponding *normalized* *opening bracket* of the pair, /// and whether or not it itself is an opening bracket. pub(crate) fn bidi_matched_opening_bracket(c: char) -> Option<BidiMatchedOpeningBracket> { for pair inself::tables::bidi_pairs_table { if pair.0 == c || pair.1 == c { let skeleton = pair.2.unwrap_or(pair.0); return Some(BidiMatchedOpeningBracket {
opening: skeleton,
is_open: pair.0 == c,
});
}
}
None
}
#[cfg(feature = "hardcoded-data")] fn bsearch_range_value_table(c: char, r: &'static [(char, char, BidiClass)]) -> BidiClass { match r.binary_search_by(|&(lo, hi, _)| { if lo <= c && c <= hi {
Equal
} elseif hi < c {
Less
} else {
Greater
}
}) {
Ok(idx) => { let (_, _, cat) = r[idx];
cat
} // UCD/extracted/DerivedBidiClass.txt: "All code points not explicitly listed // for Bidi_Class have the value Left_To_Right (L)."
Err(_) => L,
}
}
#[cfg(all(test, feature = "hardcoded-data"))] mod tests { usesuper::*;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.