Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid trailing whitespace and consecutive whitespace in OS versions #1422

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Avoid trailing whitespace and consecutive whitespace in OS versions
  • Loading branch information
dtolnay committed Dec 7, 2024
commit 2de1fa4191b450120093b27cafe8bbbb28ff4cbd
69 changes: 39 additions & 30 deletions src/unix/apple/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,40 +396,49 @@ impl SystemInner {
pub(crate) fn long_os_version() -> Option<String> {
#[cfg(target_os = "macos")]
{
let friendly_name = match Self::os_version().unwrap_or_default() {
f_n if f_n.starts_with("15") => "Sequoia",
f_n if f_n.starts_with("14") => "Sonoma",
f_n if f_n.starts_with("13") => "Ventura",
f_n if f_n.starts_with("12") => "Monterey",
f_n if f_n.starts_with("11") | f_n.starts_with("10.16") => "Big Sur",
f_n if f_n.starts_with("10.15") => "Catalina",
f_n if f_n.starts_with("10.14") => "Mojave",
f_n if f_n.starts_with("10.13") => "High Sierra",
f_n if f_n.starts_with("10.12") => "Sierra",
f_n if f_n.starts_with("10.11") => "El Capitan",
f_n if f_n.starts_with("10.10") => "Yosemite",
f_n if f_n.starts_with("10.9") => "Mavericks",
f_n if f_n.starts_with("10.8") => "Mountain Lion",
f_n if f_n.starts_with("10.7") => "Lion",
f_n if f_n.starts_with("10.6") => "Snow Leopard",
f_n if f_n.starts_with("10.5") => "Leopard",
f_n if f_n.starts_with("10.4") => "Tiger",
f_n if f_n.starts_with("10.3") => "Panther",
f_n if f_n.starts_with("10.2") => "Jaguar",
f_n if f_n.starts_with("10.1") => "Puma",
f_n if f_n.starts_with("10.0") => "Cheetah",
_ => "",
};
Some(format!(
"MacOS {} {}",
Self::os_version().unwrap_or_default(),
friendly_name
))
let mut long_name = "MacOS".to_owned();
if let Some(os_version) = Self::os_version() {
long_name.push(' ');
long_name.push_str(&os_version);
if let Some(friendly_name) = match os_version.as_str() {
f_n if f_n.starts_with("15") => Some("Sequoia"),
f_n if f_n.starts_with("14") => Some("Sonoma"),
f_n if f_n.starts_with("13") => Some("Ventura"),
f_n if f_n.starts_with("12") => Some("Monterey"),
f_n if f_n.starts_with("11") | f_n.starts_with("10.16") => Some("Big Sur"),
f_n if f_n.starts_with("10.15") => Some("Catalina"),
f_n if f_n.starts_with("10.14") => Some("Mojave"),
f_n if f_n.starts_with("10.13") => Some("High Sierra"),
f_n if f_n.starts_with("10.12") => Some("Sierra"),
f_n if f_n.starts_with("10.11") => Some("El Capitan"),
f_n if f_n.starts_with("10.10") => Some("Yosemite"),
f_n if f_n.starts_with("10.9") => Some("Mavericks"),
f_n if f_n.starts_with("10.8") => Some("Mountain Lion"),
f_n if f_n.starts_with("10.7") => Some("Lion"),
f_n if f_n.starts_with("10.6") => Some("Snow Leopard"),
f_n if f_n.starts_with("10.5") => Some("Leopard"),
f_n if f_n.starts_with("10.4") => Some("Tiger"),
f_n if f_n.starts_with("10.3") => Some("Panther"),
f_n if f_n.starts_with("10.2") => Some("Jaguar"),
f_n if f_n.starts_with("10.1") => Some("Puma"),
f_n if f_n.starts_with("10.0") => Some("Cheetah"),
_ => None,
} {
long_name.push(' ');
long_name.push_str(friendly_name);
}
}
Some(long_name)
}

#[cfg(target_os = "ios")]
{
Some(format!("iOS {}", Self::os_version().unwrap_or_default()))
let mut long_name = "iOS".to_owned();
if let Some(os_version) = Self::os_version() {
long_name.push(' ');
long_name.push_str(&os_version);
}
Some(long_name)
}
}

Expand Down
19 changes: 13 additions & 6 deletions src/unix/linux/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,19 @@ impl SystemInner {
#[cfg(not(target_os = "android"))]
let system_name = "Linux";

Some(format!(
"{} {} {}",
system_name,
Self::os_version().unwrap_or_default(),
Self::name().unwrap_or_default()
))
let mut long_name = system_name.to_owned();

if let Some(os_version) = Self::os_version() {
long_name.push(' ');
long_name.push_str(&os_version);
}

if let Some(short_name) = Self::name() {
long_name.push(' ');
long_name.push_str(&short_name);
}

Some(long_name)
}

pub(crate) fn host_name() -> Option<String> {
Expand Down
Loading