MCPcopy Create free account
hub / github.com/crosire/reshade / expand_macro_string

Function expand_macro_string

source/runtime.cpp:4669–4771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4667}
4668
4669static std::string expand_macro_string(const std::string &input, std::vector<std::pair<std::string, std::string>> macros, std::chrono::system_clock::time_point now)
4670{
4671 const auto now_seconds = std::chrono::time_point_cast<std::chrono::seconds>(now);
4672
4673 char timestamp[21];
4674 const std::time_t t = std::chrono::system_clock::to_time_t(now_seconds);
4675 struct tm tm; localtime_s(&tm, &t);
4676
4677 std::snprintf(timestamp, std::size(timestamp), "%.4d-%.2d-%.2d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
4678 macros.emplace_back("Date", timestamp);
4679 std::snprintf(timestamp, std::size(timestamp), "%.4d", tm.tm_year + 1900);
4680 macros.emplace_back("DateYear", timestamp);
4681 macros.emplace_back("Year", timestamp);
4682 std::snprintf(timestamp, std::size(timestamp), "%.2d", tm.tm_mon + 1);
4683 macros.emplace_back("DateMonth", timestamp);
4684 macros.emplace_back("Month", timestamp);
4685 std::snprintf(timestamp, std::size(timestamp), "%.2d", tm.tm_mday);
4686 macros.emplace_back("DateDay", timestamp);
4687 macros.emplace_back("Day", timestamp);
4688
4689 std::snprintf(timestamp, std::size(timestamp), "%.2d-%.2d-%.2d", tm.tm_hour, tm.tm_min, tm.tm_sec);
4690 macros.emplace_back("Time", timestamp);
4691 std::snprintf(timestamp, std::size(timestamp), "%.2d", tm.tm_hour);
4692 macros.emplace_back("TimeHour", timestamp);
4693 macros.emplace_back("Hour", timestamp);
4694 std::snprintf(timestamp, std::size(timestamp), "%.2d", tm.tm_min);
4695 macros.emplace_back("TimeMinute", timestamp);
4696 macros.emplace_back("Minute", timestamp);
4697 std::snprintf(timestamp, std::size(timestamp), "%.2d", tm.tm_sec);
4698 macros.emplace_back("TimeSecond", timestamp);
4699 macros.emplace_back("Second", timestamp);
4700 std::snprintf(timestamp, std::size(timestamp), "%.3lld", std::chrono::duration_cast<std::chrono::milliseconds>(now - now_seconds).count());
4701 macros.emplace_back("TimeMillisecond", timestamp);
4702 macros.emplace_back("Millisecond", timestamp);
4703 macros.emplace_back("TimeMS", timestamp);
4704
4705 std::string result;
4706
4707 for (size_t offset = 0, macro_beg, macro_end; offset < input.size(); offset = macro_end + 1)
4708 {
4709 macro_beg = input.find('%', offset);
4710 macro_end = input.find('%', macro_beg + 1);
4711
4712 if (macro_beg == std::string::npos || macro_end == std::string::npos)
4713 {
4714 result += input.substr(offset);
4715 break;
4716 }
4717 else
4718 {
4719 result += input.substr(offset, macro_beg - offset);
4720
4721 if (macro_end == macro_beg + 1) // Handle case of %% to escape percentage symbol
4722 {
4723 result += '%';
4724 continue;
4725 }
4726 }

Callers 2

save_screenshotMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected