| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#}; |
| 2 | |
| 3 | /// Assure that `s` is precomposed, i.e. `ä` is a single code-point, and not two i.e. `a` and `<umlaut>`. |
| 4 | /// |
| 5 | /// At the expense of extra-compute, it does nothing if there is no work to be done, returning the original input without allocating. |
| 6 | pub fn precomposerust-analyzer cargo gix-utils 0.3.5 str/precompose().(s: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str> { |
| 7 | use unicode_normalizationrust-analyzer cargo unicode-normalization 0.1.25 crate/::{UnicodeNormalizationrust-analyzer cargo unicode-normalization 0.1.25 UnicodeNormalization#, is_nfcrust-analyzer cargo unicode-normalization 0.1.25 quick_check/is_nfc().}; |
| 8 | if is_nfcrust-analyzer cargo unicode-normalization 0.1.25 quick_check/is_nfc().(s.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().()) { |
| 9 | s |
| 10 | } else { |
| 11 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(s.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().().nfcrust-analyzer cargo unicode-normalization 0.1.25 impl#[`&'a str`][`UnicodeNormalization<Chars<'a>>`]nfc().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | /// Assure that `s` is decomposed, i.e. `ä` turns into `a` and `<umlaut>`. |
| 16 | /// |
| 17 | /// At the expense of extra-compute, it does nothing if there is no work to be done, returning the original input without allocating. |
| 18 | pub fn decomposerust-analyzer cargo gix-utils 0.3.5 str/decompose().(s: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, str> { |
| 19 | use unicode_normalizationrust-analyzer cargo unicode-normalization 0.1.25 crate/::{UnicodeNormalizationrust-analyzer cargo unicode-normalization 0.1.25 UnicodeNormalization#, is_nfdrust-analyzer cargo unicode-normalization 0.1.25 quick_check/is_nfd().}; |
| 20 | if is_nfdrust-analyzer cargo unicode-normalization 0.1.25 quick_check/is_nfd().(s.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().()) { |
| 21 | s |
| 22 | } else { |
| 23 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(s.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().().nfdrust-analyzer cargo unicode-normalization 0.1.25 impl#[`&'a str`][`UnicodeNormalization<Chars<'a>>`]nfd().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /// Return the precomposed version of `path`, or `path` itself if it contained illformed unicode, |
| 28 | /// or if the unicode version didn't contains decomposed unicode. |
| 29 | /// Otherwise, similar to [`precompose()`] |
| 30 | pub fn precompose_pathrust-analyzer cargo gix-utils 0.3.5 str/precompose_path().(path: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#> { |
| 31 | match path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().() { |
| 32 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => path, |
| 33 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(maybe_decomposed) => match precomposerust-analyzer cargo gix-utils 0.3.5 str/precompose().(maybe_decomposed.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) { |
| 34 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(_) => path, |
| 35 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(precomposed) => Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(precomposed.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 36 | }, |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /// Return the precomposed version of `name`, or `name` itself if it contained illformed unicode, |
| 41 | /// or if the unicode version didn't contains decomposed unicode. |
| 42 | /// Otherwise, similar to [`precompose()`] |
| 43 | pub fn precompose_os_stringrust-analyzer cargo gix-utils 0.3.5 str/precompose_os_string().(name: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#> { |
| 44 | match name.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().() { |
| 45 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => name, |
| 46 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(maybe_decomposed) => match precomposerust-analyzer cargo gix-utils 0.3.5 str/precompose().(maybe_decomposed.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) { |
| 47 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(_) => name, |
| 48 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(precomposed) => Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(precomposed.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 49 | }, |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /// Return the precomposed version of `s`, or `s` itself if it contained illformed unicode, |
| 54 | /// or if the unicode version didn't contains decomposed unicode. |
| 55 | /// Otherwise, similar to [`precompose()`] |
| 56 | #[cfg(feature = "bstr")] |
| 57 | pub fn precompose_bstrrust-analyzer cargo gix-utils 0.3.5 str/precompose_bstr().(s: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, bstrrust-analyzer cargo bstr 1.12.3 crate/::BStrrust-analyzer cargo bstr 1.12.3 bstr/BStr#>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'_, bstrrust-analyzer cargo bstr 1.12.3 crate/::BStrrust-analyzer cargo bstr 1.12.3 bstr/BStr#> { |
| 58 | use bstrrust-analyzer cargo bstr 1.12.3 crate/::ByteSlicerust-analyzer cargo bstr 1.12.3 ext_slice/ByteSlice#; |
| 59 | match s.to_strrust-analyzer cargo bstr 1.12.3 ext_slice/ByteSlice#to_str().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() { |
| 60 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => s, |
| 61 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(maybe_decomposed) => match precomposerust-analyzer cargo gix-utils 0.3.5 str/precompose().(maybe_decomposed.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) { |
| 62 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(_) => s, |
| 63 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(precomposed) => Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(precomposed.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 64 | }, |
| 65 | } |
| 66 | } |