aboutsummaryrefslogtreecommitdiff
path: root/include/cps/Identifier.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cps/Identifier.h')
-rw-r--r--include/cps/Identifier.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/cps/Identifier.h b/include/cps/Identifier.h
new file mode 100644
index 0000000..c35f636
--- /dev/null
+++ b/include/cps/Identifier.h
@@ -0,0 +1,27 @@
+#pragma once
+#include <algorithm>
+#include <map>
+#include <set>
+#include <string>
+
+namespace cps {
+
+inline unsigned char foldIdentifier(unsigned char C) {
+ return C >= 'A' && C <= 'Z' ? C + ('a' - 'A') : C;
+}
+
+struct IdentifierLess {
+ bool operator()(const std::string &A, const std::string &B) const {
+ return std::lexicographical_compare(A.begin(), A.end(), B.begin(), B.end(),
+ [](unsigned char L, unsigned char R) { return foldIdentifier(L) < foldIdentifier(R); });
+ }
+};
+
+inline bool sameIdentifier(const std::string &A, const std::string &B) {
+ return !IdentifierLess{}(A, B) && !IdentifierLess{}(B, A);
+}
+
+template<class T> using IdentifierMap = std::map<std::string, T, IdentifierLess>;
+using IdentifierSet = std::set<std::string, IdentifierLess>;
+
+} // namespace cps