2#ifndef LIBSBX_FILESYSTEM_FILE_INFO_HPP_
3#define LIBSBX_FILESYSTEM_FILE_INFO_HPP_
8namespace sbx::filesystem {
14 file_info(
const std::string& alias_path,
const std::string& base_path,
const std::string& file_name) {
15 _initialize(alias_path, base_path, file_name);
22 inline auto filename()
const ->
const std::string& {
26 inline auto base_filename()
const ->
const std::string& {
27 return _base_filename;
30 inline auto extension()
const ->
const std::string& {
34 inline auto file_path()
const ->
const std::string& {
38 inline auto virtual_path()
const ->
const std::string& {
43 inline auto native_path()
const ->
const std::string& {
49 auto _initialize(
const std::string& alias_path,
const std::string& base_path,
const std::string& file_name) ->
void {
50 auto stripped_file_name = std::string{file_name};
52 if (!base_path.empty() && file_name.find(base_path) == 0) {
53 stripped_file_name = file_name.substr(base_path.length());
54 }
else if (!alias_path.empty() && file_name.find(alias_path) == 0) {
55 stripped_file_name = file_name.substr(alias_path.length());
58 while (!stripped_file_name.empty() && (stripped_file_name.front() ==
'/' || stripped_file_name.front() ==
'\\')) {
59 stripped_file_name.erase(stripped_file_name.begin());
62 const auto file_path = std::filesystem::path{stripped_file_name};
64 _filepath = file_path.generic_string();
65 _virtual_path = (std::filesystem::path{alias_path} / file_path).generic_string();
66 _native_path = (std::filesystem::path{base_path} / file_path).generic_string();
68 _filename = file_path.filename().string();
69 _extension = file_path.has_extension() ? file_path.extension().string() :
"";
70 _base_filename = file_path.stem().string();
73 std::string _filename;
74 std::string _base_filename;
75 std::string _extension;
77 std::string _filepath;
78 std::string _virtual_path;
79 std::string _native_path;
84 return lhs.virtual_path() == rhs.virtual_path();
87inline auto operator<(
const file_info& lhs,
const file_info& rhs) ->
bool {
88 return lhs.virtual_path() < rhs.virtual_path();
Definition: file_info.hpp:10