summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2025-03-30 14:56:49 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2025-03-30 14:56:49 +0200
commitf1b763881a5a36d63d9826fc4201e38bfc604629 (patch)
tree7d7d9514e246f46bc23ce71c99ee9d01efc8056f
parent0022a217643dd7119df5dc0fcca41161d3201acc (diff)
Handle char conversion wrt. to_lower correctly, according to cppreference.
-rw-r--r--src/util.cc12
-rw-r--r--src/util.h2
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 <fstream>
#include <algorithm>
#include <sstream>
+#include <cctype>
-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 <filesystem>
#include <cstdlib>
-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);