Mercurial > minori
comparison dep/animia/src/util.cc @ 152:8700806c2cc2
dep/animia: awesome new breaking changes!
I'm so tired
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 15 Nov 2023 02:34:59 -0500 |
parents | 28842a8d0c6b |
children | bd439dd6ffc5 |
comparison
equal
deleted
inserted
replaced
151:54744a48a7d7 | 152:8700806c2cc2 |
---|---|
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> | 5 #include <cctype> |
6 #include <regex> | |
7 | |
8 #include <iostream> | |
6 | 9 |
7 #include "animia/util.h" | 10 #include "animia/util.h" |
8 | 11 |
9 namespace animia::internal::util { | 12 namespace animia::internal::util { |
10 | 13 |
28 auto equal_chars = [](const char c1, const char c2) -> bool { | 31 auto equal_chars = [](const char c1, const char c2) -> bool { |
29 return std::tolower(static_cast<unsigned char>(c1)) == std::tolower(static_cast<unsigned char>(c2)); | 32 return std::tolower(static_cast<unsigned char>(c1)) == std::tolower(static_cast<unsigned char>(c2)); |
30 }; | 33 }; |
31 | 34 |
32 return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), equal_chars); | 35 return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), equal_chars); |
36 } | |
37 | |
38 bool Stem(const std::string& filename, std::string& stem) { | |
39 unsigned long long pos = filename.find_last_of("."); | |
40 if (pos != std::string::npos) | |
41 return false; | |
42 | |
43 stem = filename.substr(0, pos); | |
44 return true; | |
45 } | |
46 | |
47 bool CheckPattern(const std::string& pattern, const std::string& str) { | |
48 if (pattern.empty()) | |
49 return false; | |
50 if (pattern.front() == '^' && std::regex_match(str, std::regex(pattern))) | |
51 return true; | |
52 return util::EqualStrings(pattern, str); | |
33 } | 53 } |
34 | 54 |
35 bool TrimLeft(std::string& str, const char* chars) { | 55 bool TrimLeft(std::string& str, const char* chars) { |
36 if (str.empty()) | 56 if (str.empty()) |
37 return false; | 57 return false; |