Debian Codegraph @

src/utils/round_char_boundary.rs

raw symbols SCIP
1 // Taken from https://github.com/rust-lang/rust/pull/86497
2 // TODO: Remove when this is in the version of the Rust standard library that delta is building
3 // against.
4
5 #[inline]
6 const fn is_utf8_char_boundaryrust-analyzer cargo git-delta 0.19.2 utils/round_char_boundary/is_utf8_char_boundary().(b: u8) -> bool {
7 // This is bit magic equivalent to: b < 128 || b >= 192
8 (b as i8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][Neg]neg().0x40
9 }
10
11 #[inline]
12 pub fn floor_char_boundaryrust-analyzer cargo git-delta 0.19.2 utils/round_char_boundary/floor_char_boundary().(s: &str, index: usize) -> usize {
13 if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() {
14 s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()
15 } else {
16 let lower_bound = index.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(3);
17 let new_index = s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().lower_bound..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
18 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
19 .rpositionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]rposition().(|b| is_utf8_char_boundaryrust-analyzer cargo git-delta 0.19.2 utils/round_char_boundary/is_utf8_char_boundary().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b));
20
21 // SAFETY: we know that the character boundary will be within four bytes
22 unsafe { lower_bound rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().new_index.unwrap_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_unchecked().() }
23 }
24 }