diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-24 01:30:55 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-24 01:30:55 +1000 |
commit | 2798d4bf668d74028b5c1f88ae5b7b25cd08de2d (patch) | |
tree | 4a4df7c000c2e7d8be953dcf0724aa8f4b0d2b24 /source/core/StarAssetPath.hpp | |
parent | 6832c10ed5482530b4a423a78700b279fc73212a (diff) |
what the fuck it's 1:30 AM. god
Diffstat (limited to 'source/core/StarAssetPath.hpp')
-rw-r--r-- | source/core/StarAssetPath.hpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/source/core/StarAssetPath.hpp b/source/core/StarAssetPath.hpp new file mode 100644 index 0000000..e51acee --- /dev/null +++ b/source/core/StarAssetPath.hpp @@ -0,0 +1,65 @@ +#ifndef STAR_ASSET_PATH_HPP +#define STAR_ASSET_PATH_HPP + +#include "StarDirectives.hpp" + +namespace Star { + +// Asset paths are not filesystem paths. '/' is always the directory separator, +// and it is not possible to escape any asset source directory. '\' is never a +// valid directory separator. All asset paths are considered case-insensitive. +// +// In addition to the path portion of the asset path, some asset types may also +// have a sub-path, which is always separated from the path portion of the asset +// by ':'. There can be at most 1 sub-path component. +// +// Image paths may also have a directives portion of the full asset path, which +// must come after the path and optional sub-path comopnent. The directives +// portion of the path starts with a '?', and '?' separates each subsquent +// directive. +struct AssetPath { + static AssetPath split(String const& path); + static String join(AssetPath const& path); + + // Get / modify sub-path directly on a joined path string + static String setSubPath(String const& joinedPath, String const& subPath); + static String removeSubPath(String const& joinedPath); + + // Get / modify directives directly on a joined path string + static String getDirectives(String const& joinedPath); + static String addDirectives(String const& joinedPath, String const& directives); + static String removeDirectives(String const& joinedPath); + + // The base directory name for any given path, including the trailing '/'. + // Ignores sub-path and directives. + static String directory(String const& path); + + // The file part of any given path, ignoring sub-path and directives. Path + // must be a file not a directory. + static String filename(String const& path); + + // The file extension of a given file path, ignoring directives and + // sub-paths. + static String extension(String const& path); + + // Computes an absolute asset path from a relative path relative to another + // asset. The sourcePath must be an absolute path (may point to a directory + // or an asset in a directory, and ignores ':' sub-path or ? directives), + // and the givenPath may be either an absolute *or* a relative path. If it + // is an absolute path, it is returned unchanged. If it is a relative path, + // then it is computed as relative to the directory component of the + // sourcePath. + static String relativeTo(String const& sourcePath, String const& givenPath); + + String basePath; + Maybe<String> subPath; + NestedDirectives directives; + + bool operator==(AssetPath const& rhs) const; +}; + +std::ostream& operator<<(std::ostream& os, AssetPath const& rhs); + +} + +#endif
\ No newline at end of file |