}
}
+nonstd::string_view
+remove_extension(nonstd::string_view path)
+{
+ return path.substr(0, path.length() - get_extension(path).length());
+}
+
nonstd::string_view
get_truncated_base_name(nonstd::string_view path, size_t max_length)
{
// If `path` has no file extension, an empty string_view is returned.
nonstd::string_view get_extension(nonstd::string_view path);
+// Return a view into `path` containing the given path without the
+// filename extension as determined by `get_extension()`.
+nonstd::string_view remove_extension(nonstd::string_view path);
+
// Return a shortened view into the base name of `path``. This view starts at
// the beginning of the base name and ends at either the position the first dot,
// or `max_length`, or the length of the base name, whichever is the shortest.
CHECK(Util::get_extension("/foo/bar/f.abc.txt") == ".txt");
}
+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_CASE("Util:get_truncated_base_name")
{
CHECK(Util::get_truncated_base_name("", 5) == "");