libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
PathHelper.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <stdexcept>
5#include <string>
6#include "../StringHelper.h"
7
8#if __has_include(<filesystem>)
9#include <filesystem>
10namespace fs = std::filesystem;
11#else
12#include <experimental/filesystem>
13namespace fs = std::experimental::filesystem;
14#endif
15
16namespace Ship {
23 public:
29 static std::string GetFileName(const fs::path& input) {
30 // https://en.cppreference.com/w/cpp/filesystem/path/filename
31 return input.filename().string();
32 };
33
39 static std::string GetFileNameWithoutExtension(const fs::path& input) {
40 // https://en.cppreference.com/w/cpp/filesystem/path/stem
41 return input.stem().string();
42 };
43
50 static std::string GetFileNameExtension(const std::string& input) {
51 auto pos = input.find_last_of(".");
52 if (pos == std::string::npos) {
53 throw std::out_of_range("GetFileNameExtension: no '.' found in \"" + input + "\"");
54 }
55 return input.substr(pos);
56 };
57
63 static fs::path GetPath(const std::string& input) {
64 std::vector<std::string> split = StringHelper::Split(input, "/");
65 fs::path output;
66
67 for (std::string str : split) {
68 if (str.find_last_of(".") == std::string::npos) {
69 output /= str;
70 }
71 }
72
73 return output;
74 };
75
81 static fs::path GetDirectoryName(const fs::path& path) {
82 return path.parent_path();
83 };
84};
85} // namespace Ship
Utility class providing static helpers for extracting components from filesystem paths.
Definition PathHelper.h:22
static fs::path GetDirectoryName(const fs::path &path)
Returns the parent directory of the given path.
Definition PathHelper.h:81
static std::string GetFileNameExtension(const std::string &input)
Returns the file extension including the leading dot.
Definition PathHelper.h:50
static std::string GetFileNameWithoutExtension(const fs::path &input)
Returns the filename without its extension (stem).
Definition PathHelper.h:39
static fs::path GetPath(const std::string &input)
Extracts the directory portion of a slash-separated path, stripping segments that contain a dot.
Definition PathHelper.h:63
static std::string GetFileName(const fs::path &input)
Returns the filename component of a path (including extension).
Definition PathHelper.h:29
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14