3#include "Utilities/Parsing.h"
21 for (
auto & o : options) {
31 inline size_t getOption(
const std::vector<ParsedValue> & options,
const StringView & key,
const size_t defaultValue)
33 for (
auto & o : options) {
36 if (!o.asInt(value))
return defaultValue;
45 inline float getOption(
const std::vector<ParsedValue> & options,
const StringView & key,
const float defaultValue)
47 for (
auto & o : options) {
50 if (!o.asFloat(value)) value = defaultValue;
61 auto fPos = str.find(token);
63 if (fPos != std::string::npos) {
64 auto replacement = option.empty() ? direct :
getOption(options, option);
66 if (replacement.empty()) {
70 str.replace(fPos, token.length(), replacement.to_string());
76 inline std::string makeDateString(std::time_t & t,
const StringView & fmt)
82 auto & tm = *localtime(&t);
85 std::ostringstream oss;
87 oss << std::put_time(&tm, fmt.
data());
88 auto year = oss.str();
94 inline std::string
replaceFileMacros(std::string outputName,
const std::vector<ParsedValue> & options)
96 auto t = std::time(
nullptr);
98 auto year = makeDateString(t,
"%Y");
99 auto month = makeDateString(t,
"%m");
100 auto day = makeDateString(t,
"%d");
101 auto date = makeDateString(t,
"%Y-%m-%d");
103 struct TokenReplacementPair
106 const char * optionName;
109 {
"$FileName",
"stem",
nullptr},
110 {
"$Extension",
"extension",
nullptr },
111 {
"$Year",
"", year.c_str() },
112 {
"$Month",
"", month.c_str() },
113 {
"$Day",
"", day.c_str() },
114 {
"$Date",
"", date.c_str() },
117 for (
auto & p : tokens) {
118 replaceToken(outputName, options, p.token, p.optionName, p.direct);
128 for (
auto c : filename) {
Provides a weakly referenced view over the contents of a string.
constexpr const char * data() const noexcept
Get the sequence of characters referenced by the string view.
Contains code for composing and managing entities built from components.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
bool replaceToken(std::string &str, const std::vector< ParsedValue > &options, const std::string token, const StringView &option, const StringView &direct)
Check string for the given token. Replace with option string is set else direct value.
std::string replaceFileMacros(std::string outputName, const std::vector< ParsedValue > &options)
Replace common macroes for file name generation. I.e.: "A/$Filename" etc.
std::string fixInvalidPathChars(const std::string &filename)
Remove characters that are not valid for filenames lik "<>:/\?" etc.
StringView getOption(const std::vector< ParsedValue > &options, const StringView &key, const StringView &defaultValue="")
Find and get value of option in vector as a string. Return default if not found.