diff dep/animia/src/util.cc @ 153:bd439dd6ffc5

*: make win stuff actually work, rename bsd.cc to xnu.cc It's been OS X only for ages, and these functions are different between most BSDs anyway
author Paper <mrpapersonic@gmail.com>
date Wed, 15 Nov 2023 13:28:18 -0500
parents 8700806c2cc2
children cdf79282d647
line wrap: on
line diff
--- a/dep/animia/src/util.cc	Wed Nov 15 02:34:59 2023 -0500
+++ b/dep/animia/src/util.cc	Wed Nov 15 13:28:18 2023 -0500
@@ -2,7 +2,6 @@
 #include <fstream>
 #include <sstream>
 #include <string>
-#include <cctype>
 #include <regex>
 
 #include <iostream>
@@ -27,12 +26,17 @@
 	return true;
 }
 
+/* this assumes ASCII... which really should be the case for what we need, anyway */
 bool EqualStrings(const std::string& str1, const std::string& str2) {
-	auto equal_chars = [](const char c1, const char c2) -> bool {
-		return std::tolower(static_cast<unsigned char>(c1)) == std::tolower(static_cast<unsigned char>(c2));
+	auto tolower = [](const char c) -> char {
+		return ('A' <= c && c <= 'Z') ? c + ('a' - 'A') : c;
 	};
 
-	return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), equal_chars);
+	auto equal_chars = [&tolower](const char c1, const char c2) -> bool {
+		return tolower(c1) == tolower(c2);
+	};
+
+	return str1.length() == str2.length() && std::equal(str1.begin(), str1.end(), str2.begin(), equal_chars);
 }
 
 bool Stem(const std::string& filename, std::string& stem) {