From 63277a52115f24c42c05d75313ec0ce191043e57 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 25 Jan 2025 20:43:33 +0100 Subject: [PATCH] chore: Simplify util::add_exe_suffix --- src/ccache/util/path.cpp | 9 ++------- src/ccache/util/path.hpp | 5 ++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/ccache/util/path.cpp b/src/ccache/util/path.cpp index 6c3376c3..434ed20f 100644 --- a/src/ccache/util/path.cpp +++ b/src/ccache/util/path.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2024 Joel Rosdahl and other contributors +// Copyright (C) 2021-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -36,12 +36,7 @@ namespace util { std::string add_exe_suffix(const std::string& program) { - std::string ext = util::to_lowercase(fs::path(program).extension().string()); - if (ext == ".exe" || ext == ".bat" || ext == ".cmd" || ext == ".sh") { - return program; - } else { - return program + ".exe"; - } + return fs::path(program).has_extension() ? program : program + ".exe"; } fs::path diff --git a/src/ccache/util/path.hpp b/src/ccache/util/path.hpp index fe850ef4..8e566ac4 100644 --- a/src/ccache/util/path.hpp +++ b/src/ccache/util/path.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2024 Joel Rosdahl and other contributors +// Copyright (C) 2021-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -31,8 +31,7 @@ namespace util { // --- Interface --- -// Add ".exe" suffix to `program` if it doesn't already end with ".exe", ".bat", -// ".cmd" or ".sh". +// Add ".exe" suffix to `program` if it doesn't already have an extension. std::string add_exe_suffix(const std::string& program); // Return a new path with `extension` added to `path` (keeping any existing -- 2.47.2