diff options
| author | FlafyDev <flafyarazi@gmail.com> | 2022-08-19 23:18:09 +0300 |
|---|---|---|
| committer | FlafyDev <flafyarazi@gmail.com> | 2022-08-19 23:18:09 +0300 |
| commit | f0ad77251b28fcf48dcaf25f23e3a140d69a4735 (patch) | |
| tree | 4a4b96c67ced9d14c1850b466eb2b6f8587140b3 /src/helpers/MiscFunctions.cpp | |
| parent | 69d17bf4240e41f2b26abd7a46dfd0e754e9ee9e (diff) | |
move absolutePath to MiscFunctions
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index b7285637..b27489ca 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -40,6 +40,28 @@ static const float transforms[][9] = {{ }, }; +std::string absolutePath(const std::string& rawpath, const std::string& currentPath) { + auto value = rawpath; + + if (value[0] == '.') { + auto currentDir = currentPath.substr(0, currentPath.find_last_of('/')); + + if (value[1] == '.') { + auto parentDir = currentDir.substr(0, currentDir.find_last_of('/')); + value.replace(0, 2, parentDir); + } else { + value.replace(0, 1, currentDir); + } + } + + if (value[0] == '~') { + static const char* const ENVHOME = getenv("HOME"); + value.replace(0, 1, std::string(ENVHOME)); + } + + return value; +} + void addWLSignal(wl_signal* pSignal, wl_listener* pListener, void* pOwner, std::string ownerString) { ASSERT(pSignal); ASSERT(pListener); |
