| @@ -12,21 +12,23 @@ pub fn agent() -> &'static str { · 11 unmodified lines |
| 12 | concat!("oxide-", env!("CARGO_PKG_VERSION")) | 12 | concat!("oxide-", env!("CARGO_PKG_VERSION")) |
| 13 | } | 13 | } |
| 14 | | 14 | |
| 15 | /// Equivalent to `std::env::args_os()`, but with precomposed unicode on `MacOS` and other apple platforms. | | |
| 16 | #[cfg(not(target_vendor = "apple"))] | | |
| 17 | pub fn args_os() -> impl Iterator<Item = OsString> { | | |
| 18 | std::env::args_os() | | |
| 19 | } | | |
| 20 | | | |
| 21 | /// Equivalent to `std::env::args_os()`, but with precomposed unicode on MacOS and other apple platforms. | 15 | /// Equivalent to `std::env::args_os()`, but with precomposed unicode on MacOS and other apple platforms. |
| | 16 | /// It does not change the input arguments on any other platform. |
| 22 | /// | 17 | /// |
| 23 | /// Note that this ignores `core.precomposeUnicode` as git-config isn't available yet. It's default enabled in modern git though. | 18 | /// Note that this ignores `core.precomposeUnicode` as git-config isn't available yet. It's default enabled in modern git though, |
| 24 | #[cfg(target_vendor = "apple")] | 19 | /// and generally decomposed unicode is nothing one would want in a git repository. |
| 25 | pub fn args_os() -> impl Iterator<Item = OsString> { | 20 | pub fn args_os() -> impl Iterator<Item = OsString> { |
| 26 | use unicode_normalization::UnicodeNormalization; | 21 | args_os_opt(cfg!(target_vendor = "apple")) |
| 27 | std::env::args_os().map(|arg| match arg.to_str() { | 22 | } |
| 28 | Some(arg) => arg.nfc().collect::<String>().into(), | 23 | |
| 29 | None => arg, | 24 | /// Like [`args_os()`], but with the `precompose_unicode` parameter akin to `core.precomposeUnicode` in the Git configuration. |
| | 25 | pub fn args_os_opt(precompose_unicode: bool) -> impl Iterator<Item = OsString> { |
| | 26 | std::env::args_os().map(move |arg| { |
| | 27 | if precompose_unicode { |
| | 28 | gix_utils::str::precompose_os_string(arg.into()).into_owned() |
| | 29 | } else { |
| | 30 | arg |
| | 31 | } |
| 30 | }) | 32 | }) |
| 31 | } | 33 | } |
| 32 | | 34 | |