Merge pull request #10 from VPeruS/ranges
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run

Replace heap allocation with view
This commit is contained in:
Kelsi Rae Davis 2026-03-06 16:49:32 -08:00 committed by GitHub
commit d6de60e413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,9 @@
#include <cstdlib> #include <cstdlib>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <cstring>
#include <iterator>
#include <ranges>
namespace wowee { namespace wowee {
namespace core { namespace core {
@ -42,15 +45,16 @@ void Logger::ensureFile() {
} }
} }
if (const char* level = std::getenv("WOWEE_LOG_LEVEL")) { if (const char* level = std::getenv("WOWEE_LOG_LEVEL")) {
std::string v(level); auto toLower = [] (unsigned char c) { return std::tolower(c); };
std::transform(v.begin(), v.end(), v.begin(), [](unsigned char c) { using namespace std::literals;
return static_cast<char>(std::tolower(c));
}); auto v = std::string_view{level} | std::views::transform(toLower);
if (v == "debug") setLogLevel(LogLevel::DEBUG); if (std::ranges::equal(v, "debug"sv)) setLogLevel(LogLevel::DEBUG);
else if (v == "info") setLogLevel(LogLevel::INFO); else if (std::ranges::equal(v, "info"sv)) setLogLevel(LogLevel::INFO);
else if (v == "warn" || v == "warning") setLogLevel(LogLevel::WARNING); else if (std::ranges::equal(v, "warn"sv) || std::ranges::equal(v, "warning"sv))
else if (v == "error") setLogLevel(kLogLevelError); setLogLevel(LogLevel::WARNING);
else if (v == "fatal") setLogLevel(LogLevel::FATAL); else if (std::ranges::equal(v, "error"sv)) setLogLevel(kLogLevelError);
else if (std::ranges::equal(v, "fatal"sv)) setLogLevel(LogLevel::FATAL);
} }
std::error_code ec; std::error_code ec;
std::filesystem::create_directories("logs", ec); std::filesystem::create_directories("logs", ec);