summaryrefslogtreecommitdiffhomepage
path: root/include/unicode/predicate.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2022-01-01 20:25:34 +0100
committerRoland Reichwein <mail@reichwein.it>2022-01-01 20:25:34 +0100
commit52d4375b10d920a59f1309c272a2e525feb1c25d (patch)
tree9d5417a9d214f4b0ba68b75e8908e28da46dd5c8 /include/unicode/predicate.h
parentae7b430afd1239947b8f8b2d9dc0ca72dbce91ac (diff)
Separated out headers files; optimizations; type traits; better naming
Diffstat (limited to 'include/unicode/predicate.h')
-rw-r--r--include/unicode/predicate.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/unicode/predicate.h b/include/unicode/predicate.h
new file mode 100644
index 0000000..5f8c6a4
--- /dev/null
+++ b/include/unicode/predicate.h
@@ -0,0 +1,21 @@
+#pragma once
+
+namespace unicode {
+
+ // bits_to_compare: limit bits to consider even further than defined by T
+ // T: usually, char32_t, uint32_t etc.
+ template<size_t bits_to_compare = 32, typename T>
+ static inline bool is_valid_unicode(const T& value) noexcept
+ {
+ if constexpr(sizeof(T) == 1 || bits_to_compare <= 15)
+ return true;
+ else if constexpr(sizeof(T) == 2 || bits_to_compare <= 20)
+ //return value <= 0xD7FF || value >= 0xE000;
+ return (value & 0xF800) != 0xD800;
+ else
+ //return (value & 0xFFFFF800) != 0x0000D800 && (value >> 16) <= 0x10;
+ return value <= 0xD7FF || (value >= 0xE000 && value <= 0x10FFFF);
+ }
+
+} // namespace unicode
+