From f1b763881a5a36d63d9826fc4201e38bfc604629 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 30 Mar 2025 14:56:49 +0200 Subject: Handle char conversion wrt. to_lower correctly, according to cppreference. --- src/util.cc | 12 ++++++++---- src/util.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/util.cc b/src/util.cc index 6fc650a..9052118 100644 --- a/src/util.cc +++ b/src/util.cc @@ -7,12 +7,16 @@ #include #include #include +#include -std::string to_lower(const std::string& str) +std::string to_lower(std::string str) { - std::string out{str}; - std::transform(out.begin(), out.end(), out.begin(), ::tolower); - return out; + std::transform(str.begin(), str.end(), str.begin(), + [](unsigned char c) + { + return std::tolower(c); + }); + return str; } std::string readFile(const std::string& fileName) diff --git a/src/util.h b/src/util.h index 8b41014..6e1bc7b 100644 --- a/src/util.h +++ b/src/util.h @@ -9,7 +9,7 @@ #include #include -std::string to_lower(const std::string& str); +std::string to_lower(std::string str); std::string readFile(const std::string& fileName); ctor::language languageFromExtension(const std::filesystem::path& file); -- cgit v1.2.3