关键节点
This commit is contained in:
54
editor/app/Support/EnvironmentFlags.h
Normal file
54
editor/app/Support/EnvironmentFlags.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
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::App
|
||||
Reference in New Issue
Block a user