libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Path.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
19class Path {
20 public:
26 static std::string GetFileName(const fs::path& input) {
27 // https://en.cppreference.com/w/cpp/filesystem/path/filename
28 return input.filename().string();
29 };
30
36 static std::string GetFileNameWithoutExtension(const fs::path& input) {
37 // https://en.cppreference.com/w/cpp/filesystem/path/stem
38 return input.stem().string();
39 };
40
47 static std::string GetFileNameExtension(const std::string& input) {
48 auto pos = input.find_last_of(".");
49 if (pos == std::string::npos) {
50 throw std::out_of_range("GetFileNameExtension: no '.' found in \"" + input + "\"");
51 }
52 return input.substr(pos);
53 };
54
60 static fs::path GetPath(const std::string& input) {
61 std::vector<std::string> split = StringHelper::Split(input, "/");
62 fs::path output;
63
64 for (std::string str : split) {
65 if (str.find_last_of(".") == std::string::npos)
66 output /= str;
67 }
68
69 return output;
70 };
71
77 static fs::path GetDirectoryName(const fs::path& path) {
78 return path.parent_path();
79 };
80};