55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
#include <cstdlib>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
namespace XCEngine::UI::Editor::Support {
|
|
|
|
inline bool IsEnvironmentFlagEnabled(const char* envName) {
|
|
if (envName == nullptr || envName[0] == '\0') {
|
|
return false;
|
|
}
|
|
|
|
const char* value = std::getenv(envName);
|
|
if (value == nullptr || value[0] == '\0') {
|
|
return false;
|
|
}
|
|
|
|
std::string normalized = value;
|
|
std::transform(
|
|
normalized.begin(),
|
|
normalized.end(),
|
|
normalized.begin(),
|
|
[](unsigned char character) {
|
|
return static_cast<char>(std::tolower(character));
|
|
});
|
|
return normalized != "0" &&
|
|
normalized != "false" &&
|
|
normalized != "off" &&
|
|
normalized != "no";
|
|
}
|
|
|
|
inline std::optional<int> TryGetEnvironmentInt(const char* envName) {
|
|
if (envName == nullptr || envName[0] == '\0') {
|
|
return std::nullopt;
|
|
}
|
|
|
|
const char* value = std::getenv(envName);
|
|
if (value == nullptr || value[0] == '\0') {
|
|
return std::nullopt;
|
|
}
|
|
|
|
char* parseEnd = nullptr;
|
|
const long parsed = std::strtol(value, &parseEnd, 10);
|
|
if (parseEnd == value || (parseEnd != nullptr && *parseEnd != '\0')) {
|
|
return std::nullopt;
|
|
}
|
|
|
|
return static_cast<int>(parsed);
|
|
}
|
|
|
|
} // namespace XCEngine::UI::Editor::Support
|