1#ifndef TOOL_AYON_ROT_HELPERS_DEF
2#define TOOL_AYON_ROT_HELPERS_DEF
4#include "../../../../NameSpaceDef/namespaces.hpp"
5#include "../../lib/logging/AyonLogger.hpp"
10#include <unordered_map>
22rootReplace(
const std::string &rootLessPath,
const std::unordered_map<std::string, std::string> &siteRoots) {
24 static const std::string kLogKeyName =
"rootReplace";
25 static const bool kRegistered = logger.registerLoggingKey(kLogKeyName);
28 auto logKey = logger.key(kLogKeyName);
30 std::string rootedPath;
33 std::regex rootFindPattern(
"\\{root\\[.*?\\]\\}");
34 if (std::regex_search(rootLessPath, matchea, rootFindPattern)) {
35 std::string siteRootOverwriteName = matchea.str(0);
38 std::regex rootBracketPattern(
"\\[(.*?)\\]");
39 if (std::regex_search(siteRootOverwriteName, matcheb, rootBracketPattern)) {
40 std::string key = matcheb.str(1);
42 std::string replacement = siteRoots.at(key);
43 rootedPath = std::regex_replace(rootLessPath, rootFindPattern, replacement);
44 std::replace(rootedPath.begin(), rootedPath.end(),
'\\',
'/');
47 catch (std::out_of_range &e) {
48 logger.warn(logKey,
"Could not find site root '{}' for path '{}'", key, rootLessPath);
static AyonLogger & getInstance()
Definition: AyonLogger.hpp:33
#define YNPUT_TOOL_AYON_NAMESPACE_CLOSE
Definition: namespaces.hpp:106
#define YNPUT_TOOL_AYON_NAMESPACE_OPEN
Definition: namespaces.hpp:105
YNPUT_TOOL_AYON_NAMESPACE_OPEN std::string rootReplace(const std::string &rootLessPath, const std::unordered_map< std::string, std::string > &siteRoots)
allows to replace the {root[xxx]} key from an Ayon resolver endpoint with the local root overwrites
Definition: rootHelpers.hpp:22