#pragma once #include "il2cpp-config.h" #include #include "StringViewUtils.h" namespace il2cpp { namespace utils { namespace PathUtils { std::string BasenameNoExtension(const std::string& path); std::string PathNoExtension(const std::string& path); template std::basic_string Basename(const utils::StringView& path) { if (path.IsEmpty()) return std::basic_string(1, static_cast('.')); const size_t pos = path.RFind(IL2CPP_DIR_SEPARATOR); // No seperators. Path is filename if (pos == utils::StringView::NPos()) return std::basic_string(path.Str(), path.Length()); return std::basic_string(path.Str() + pos + 1, path.Length() - pos - 1); } template std::basic_string Basename(const std::basic_string& path) { return Basename(STRING_TO_STRINGVIEW(path)); } template std::basic_string DirectoryName(const utils::StringView& path) { if (path.IsEmpty()) return std::basic_string(); const size_t pos = path.RFind(IL2CPP_DIR_SEPARATOR); if (pos == utils::StringView::NPos()) return std::basic_string(1, static_cast('.')); if (pos == 0) return std::basic_string(1, static_cast('/')); return std::basic_string(path.Str(), pos); } template std::basic_string Combine(const utils::StringView& path1, const utils::StringView& path2) { std::basic_string result; result.reserve(path1.Length() + path2.Length() + 1); result.append(path1.Str(), path1.Length()); result.append(1, static_cast(IL2CPP_DIR_SEPARATOR)); result.append(path2.Str(), path2.Length()); return result; } template std::basic_string DirectoryName(const std::basic_string& path) { return DirectoryName(STRING_TO_STRINGVIEW(path)); } template std::basic_string Combine(const std::basic_string& path1, const std::basic_string& path2) { return Combine(STRING_TO_STRINGVIEW(path1), STRING_TO_STRINGVIEW(path2)); } template std::basic_string Combine(const std::basic_string& path1, const utils::StringView& path2) { return Combine(STRING_TO_STRINGVIEW(path1), path2); } template std::basic_string Combine(const utils::StringView& path1, const std::basic_string& path2) { return Combine(path1, STRING_TO_STRINGVIEW(path2)); } } } /* utils */ } /* il2cpp */