: path;
}
-std::string_view
-remove_extension(std::string_view path)
-{
- return path.substr(
- 0, path.length() - fs::path(path).extension().native().length());
-}
-
} // namespace Util
// normalized result doesn't resolve to the same file system entry as `path`.
std::string normalize_concrete_absolute_path(const std::string& path);
-// Return a view into `path` containing the given path without the filename
-// extension as determined by `get_extension()`.
-std::string_view remove_extension(std::string_view path);
-
} // namespace Util
const auto output_dir = fs::path(ctx.args_info.output_obj).parent_path();
dir = fs::canonical(output_dir).value_or(output_dir).string();
}
- std::string_view stem = Util::remove_extension(
- fs::path(ctx.args_info.output_obj).filename().string());
- std::string gcda_path = FMT("{}/{}.gcda", dir, stem);
+ std::string gcda_path =
+ FMT("{}/{}.gcda", dir, fs::path(ctx.args_info.output_obj).stem());
LOG("Hashing coverage path {}", gcda_path);
hash.hash_delimiter("gcda");
hash.hash(gcda_path);
hash_profile_data_file(const Context& ctx, Hash& hash)
{
const std::string& profile_path = ctx.args_info.profile_path;
- std::string_view base_name = Util::remove_extension(ctx.args_info.output_obj);
+ const std::string base_name =
+ fs::path(ctx.args_info.output_obj).replace_extension("").string();
std::string hashified_cwd = ctx.apparent_cwd;
std::replace(hashified_cwd.begin(), hashified_cwd.end(), '/', '#');
case 'V': // --version
{
- std::string name = fs::path(argv[0]).filename().string();
-#ifdef _WIN32
- name = Util::remove_extension(name);
-#endif
- PRINT_RAW(stdout, get_version_text(name));
+ PRINT_RAW(stdout, get_version_text(fs::path(argv[0]).stem().string()));
break;
}
#endif
}
-TEST_CASE("Util::remove_extension")
-{
- CHECK(Util::remove_extension("") == "");
- CHECK(Util::remove_extension(".") == ".");
- CHECK(Util::remove_extension("...") == "..");
- CHECK(Util::remove_extension("foo") == "foo");
- CHECK(Util::remove_extension("/") == "/");
- CHECK(Util::remove_extension("/foo") == "/foo");
- CHECK(Util::remove_extension("/foo/bar/f") == "/foo/bar/f");
- CHECK(Util::remove_extension("f.txt") == "f");
- CHECK(Util::remove_extension("f.abc.txt") == "f.abc");
- CHECK(Util::remove_extension("/foo/bar/f.txt") == "/foo/bar/f");
- CHECK(Util::remove_extension("/foo/bar/f.abc.txt") == "/foo/bar/f.abc");
-}
-
TEST_SUITE_END();