1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::ffi::{OsStr, OsString};
use crate::bstr::{BString, ByteVec};
#[cfg(not(target_vendor = "apple"))]
pub fn args_os() -> impl Iterator<Item = OsString> {
std::env::args_os()
}
#[cfg(target_vendor = "apple")]
pub fn args_os() -> impl Iterator<Item = OsString> {
use unicode_normalization::UnicodeNormalization;
std::env::args_os().map(|arg| match arg.to_str() {
Some(arg) => arg.nfc().collect::<String>().into(),
None => arg,
})
}
pub fn os_str_to_bstring(input: &OsStr) -> Result<BString, String> {
Vec::from_os_string(input.into())
.map(Into::into)
.map_err(|_| input.to_string_lossy().into_owned())
}