• Home
  • Raw
  • Download

Lines Matching full:level

2 // COPYRIGHT file at the top-level directory of this distribution.
10 //! Bidi Embedding Level
12 //! See [`Level`](struct.Level.html) for more details.
20 /// Embedding Level
25 /// This struct maintains a *valid* status for level numbers, meaning that creating a new level, or
26 /// mutating an existing level, with the value smaller than `0` (before conversion to `u8`) or
32 pub struct Level(u8); struct
34 pub const LTR_LEVEL: Level = Level(0);
35 pub const RTL_LEVEL: Level = Level(1);
38 /// During explicit level resolution, embedding level can go as high as `max_depth`.
40 /// During implicit level resolution, embedding level can go as high as `max_depth + 1`.
43 /// Errors that can occur on Level creation or mutation
46 /// Out-of-range (invalid) embedding level number.
50 impl Level { implementation
51 /// New LTR level with smallest number value (0).
53 pub fn ltr() -> Level { in ltr()
57 /// New RTL level with smallest number value (1).
59 pub fn rtl() -> Level { in rtl()
75 /// Create new level, fail if number is larger than `max_depth + 1`.
77 pub fn new(number: u8) -> Result<Level, Error> { in new() argument
79 Ok(Level(number)) in new()
85 /// Create new level, fail if number is larger than `max_depth`.
87 pub fn new_explicit(number: u8) -> Result<Level, Error> { in new_explicit() argument
89 Ok(Level(number)) in new_explicit()
97 /// The level number.
103 /// If this level is left-to-right.
109 /// If this level is right-to-left.
117 /// Raise level by `amount`, fail if number is larger than `max_depth + 1`.
133 /// Raise level by `amount`, fail if number is larger than `max_depth`.
149 /// Lower level by `amount`, fail if number goes below zero.
163 /// The next LTR (even) level greater than this, or fail if number is larger than `max_depth`.
165 pub fn new_explicit_next_ltr(&self) -> Result<Level, Error> { in new_explicit_next_ltr() argument
166 Level::new_explicit((self.0 + 2) & !1) in new_explicit_next_ltr()
169 /// The next RTL (odd) level greater than this, or fail if number is larger than `max_depth`.
171 pub fn new_explicit_next_rtl(&self) -> Result<Level, Error> { in new_explicit_next_rtl() argument
172 Level::new_explicit((self.0 + 1) | 1) in new_explicit_next_rtl()
175 /// The lowest RTL (odd) level greater than or equal to this, or fail if number is larger than
178 pub fn new_lowest_ge_rtl(&self) -> Result<Level, Error> { in new_lowest_ge_rtl() argument
179 Level::new(self.0 | 1) in new_lowest_ge_rtl()
182 /// Generate a character type based on a level (as specified in steps X10 and N2).
192 pub fn vec(v: &[u8]) -> Vec<Level> { in vec() argument
197 /// If levels has any RTL (odd) level
199 /// This information is usually used to skip re-ordering of text when no RTL level is present
201 pub fn has_rtl(levels: &[Level]) -> bool { in has_rtl()
205 impl Into<u8> for Level { implementation
206 /// Convert to the level number
213 impl From<u8> for Level { implementation
214 /// Create level by number
216 fn from(number: u8) -> Level { in from() argument
217 Level::new(number).expect("Level number error") in from()
222 impl<'a> PartialEq<&'a str> for Level { implementation
230 impl<'a> PartialEq<String> for Level { implementation
243 assert_eq!(Level::new(0), Ok(Level(0))); in test_new()
244 assert_eq!(Level::new(1), Ok(Level(1))); in test_new()
245 assert_eq!(Level::new(10), Ok(Level(10))); in test_new()
246 assert_eq!(Level::new(125), Ok(Level(125))); in test_new()
247 assert_eq!(Level::new(126), Ok(Level(126))); in test_new()
248 assert_eq!(Level::new(127), Err(Error::OutOfRangeNumber)); in test_new()
249 assert_eq!(Level::new(255), Err(Error::OutOfRangeNumber)); in test_new()
254 assert_eq!(Level::new_explicit(0), Ok(Level(0))); in test_new_explicit()
255 assert_eq!(Level::new_explicit(1), Ok(Level(1))); in test_new_explicit()
256 assert_eq!(Level::new_explicit(10), Ok(Level(10))); in test_new_explicit()
257 assert_eq!(Level::new_explicit(125), Ok(Level(125))); in test_new_explicit()
258 assert_eq!(Level::new_explicit(126), Err(Error::OutOfRangeNumber)); in test_new_explicit()
259 assert_eq!(Level::new_explicit(255), Err(Error::OutOfRangeNumber)); in test_new_explicit()
264 assert_eq!(Level(0).is_ltr(), true); in test_is_ltr()
265 assert_eq!(Level(1).is_ltr(), false); in test_is_ltr()
266 assert_eq!(Level(10).is_ltr(), true); in test_is_ltr()
267 assert_eq!(Level(11).is_ltr(), false); in test_is_ltr()
268 assert_eq!(Level(124).is_ltr(), true); in test_is_ltr()
269 assert_eq!(Level(125).is_ltr(), false); in test_is_ltr()
274 assert_eq!(Level(0).is_rtl(), false); in test_is_rtl()
275 assert_eq!(Level(1).is_rtl(), true); in test_is_rtl()
276 assert_eq!(Level(10).is_rtl(), false); in test_is_rtl()
277 assert_eq!(Level(11).is_rtl(), true); in test_is_rtl()
278 assert_eq!(Level(124).is_rtl(), false); in test_is_rtl()
279 assert_eq!(Level(125).is_rtl(), true); in test_is_rtl()
284 let mut level = Level::ltr(); in test_raise() localVariable
285 assert_eq!(level.number(), 0); in test_raise()
286 assert!(level.raise(100).is_ok()); in test_raise()
287 assert_eq!(level.number(), 100); in test_raise()
288 assert!(level.raise(26).is_ok()); in test_raise()
289 assert_eq!(level.number(), 126); in test_raise()
290 assert!(level.raise(1).is_err()); // invalid! in test_raise()
291 assert!(level.raise(250).is_err()); // overflow! in test_raise()
292 assert_eq!(level.number(), 126); in test_raise()
297 let mut level = Level::ltr(); in test_raise_explicit() localVariable
298 assert_eq!(level.number(), 0); in test_raise_explicit()
299 assert!(level.raise_explicit(100).is_ok()); in test_raise_explicit()
300 assert_eq!(level.number(), 100); in test_raise_explicit()
301 assert!(level.raise_explicit(25).is_ok()); in test_raise_explicit()
302 assert_eq!(level.number(), 125); in test_raise_explicit()
303 assert!(level.raise_explicit(1).is_err()); // invalid! in test_raise_explicit()
304 assert!(level.raise_explicit(250).is_err()); // overflow! in test_raise_explicit()
305 assert_eq!(level.number(), 125); in test_raise_explicit()
310 let mut level = Level::rtl(); in test_lower() localVariable
311 assert_eq!(level.number(), 1); in test_lower()
312 assert!(level.lower(1).is_ok()); in test_lower()
313 assert_eq!(level.number(), 0); in test_lower()
314 assert!(level.lower(1).is_err()); // underflow! in test_lower()
315 assert!(level.lower(250).is_err()); // underflow! in test_lower()
316 assert_eq!(level.number(), 0); in test_lower()
321 assert_eq!(has_rtl(&Level::vec(&[0, 0, 0])), false); in test_has_rtl()
322 assert_eq!(has_rtl(&Level::vec(&[0, 1, 0])), true); in test_has_rtl()
323 assert_eq!(has_rtl(&Level::vec(&[0, 2, 0])), false); in test_has_rtl()
324 assert_eq!(has_rtl(&Level::vec(&[0, 125, 0])), true); in test_has_rtl()
325 assert_eq!(has_rtl(&Level::vec(&[0, 126, 0])), false); in test_has_rtl()
330 let level = Level::rtl(); in test_into() localVariable
331 assert_eq!(1u8, level.into()); in test_into()
337 Level::vec(&[0, 1, 125]), in test_vec()
338 vec![Level(0), Level(1), Level(125)] in test_vec()
344 assert_eq!(Level::vec(&[0, 1, 4, 125]), vec!["0", "1", "x", "125"]); in test_str_eq()
345 assert_ne!(Level::vec(&[0, 1, 4, 125]), vec!["0", "1", "5", "125"]); in test_str_eq()
351 Level::vec(&[0, 1, 4, 125]), in test_string_eq()
365 &Level::ltr(), in test_statics()
366 &[Token::NewtypeStruct { name: "Level" }, Token::U8(0)], in test_statics()
369 &Level::rtl(), in test_statics()
370 &[Token::NewtypeStruct { name: "Level" }, Token::U8(1)], in test_statics()
376 let level = Level::new(42).unwrap(); in test_new() localVariable
378 &level, in test_new()
379 &[Token::NewtypeStruct { name: "Level" }, Token::U8(42)], in test_new()