Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 152:8700806c2cc2 | 153:bd439dd6ffc5 |
|---|---|
| 1 #include <algorithm> | 1 #include <algorithm> |
| 2 #include <fstream> | 2 #include <fstream> |
| 3 #include <sstream> | 3 #include <sstream> |
| 4 #include <string> | 4 #include <string> |
| 5 #include <cctype> | |
| 6 #include <regex> | 5 #include <regex> |
| 7 | 6 |
| 8 #include <iostream> | 7 #include <iostream> |
| 9 | 8 |
| 10 #include "animia/util.h" | 9 #include "animia/util.h" |
| 25 file.close(); | 24 file.close(); |
| 26 | 25 |
| 27 return true; | 26 return true; |
| 28 } | 27 } |
| 29 | 28 |
| 29 /* this assumes ASCII... which really should be the case for what we need, anyway */ | |
| 30 bool EqualStrings(const std::string& str1, const std::string& str2) { | 30 bool EqualStrings(const std::string& str1, const std::string& str2) { |
| 31 auto equal_chars = [](const char c1, const char c2) -> bool { | 31 auto tolower = [](const char c) -> char { |
| 32 return std::tolower(static_cast<unsigned char>(c1)) == std::tolower(static_cast<unsigned char>(c2)); | 32 return ('A' <= c && c <= 'Z') ? c + ('a' - 'A') : c; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), equal_chars); | 35 auto equal_chars = [&tolower](const char c1, const char c2) -> bool { |
| 36 return tolower(c1) == tolower(c2); | |
| 37 }; | |
| 38 | |
| 39 return str1.length() == str2.length() && std::equal(str1.begin(), str1.end(), str2.begin(), equal_chars); | |
| 36 } | 40 } |
| 37 | 41 |
| 38 bool Stem(const std::string& filename, std::string& stem) { | 42 bool Stem(const std::string& filename, std::string& stem) { |
| 39 unsigned long long pos = filename.find_last_of("."); | 43 unsigned long long pos = filename.find_last_of("."); |
| 40 if (pos != std::string::npos) | 44 if (pos != std::string::npos) |
