aboutsummaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-02-15 12:48:35 +0100
committerAdrian Kummerländer2014-02-15 12:48:35 +0100
commit79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c (patch)
tree09a09025f16b79d5d46201c77bb5cab2d2bdd4f6 /src/utility.h
parent609be30bf9562a86182ed0958a238b6ba9392ebf (diff)
downloadCodepointIterator-79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c.tar
CodepointIterator-79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c.tar.gz
CodepointIterator-79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c.tar.bz2
CodepointIterator-79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c.tar.lz
CodepointIterator-79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c.tar.xz
CodepointIterator-79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c.tar.zst
CodepointIterator-79a65ce58ad8f3b2b1c9eeaba4b0b4710dc09e2c.zip
Extracted helper functions and bitmasks into separate compilation unit
* utility.h and utility.cc now contain the UTF8-codepoint and unit bitmasks and read / write functions * Modified users of these functions and unions accordingly * Added the new compilation unit to the Makefile * Changed bitmask specification from plain integer literals to shift expressions for better readability
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h
new file mode 100644
index 0000000..dcdcf75
--- /dev/null
+++ b/src/utility.h
@@ -0,0 +1,29 @@
+#ifndef CODEPOINT_ITERATOR_UTILITY_H_
+#define CODEPOINT_ITERATOR_UTILITY_H_
+
+#include <cstdint>
+
+namespace UTF8 {
+namespace dtl {
+
+enum class CodeUnitType : uint8_t {
+ CONTINUATION = (128 >> 0), // 10000000
+ LEADING = (128 >> 1), // 01000000
+ THREE = (128 >> 2), // 00100000
+ FOUR = (128 >> 3), // 00010000
+};
+
+enum class CodePoint : uint8_t {
+ CONTINUATION = (UINT8_MAX >> 2), // 00111111
+ TWO = (UINT8_MAX >> 3), // 00011111
+ THREE = (UINT8_MAX >> 4), // 00001111
+ FOUR = (UINT8_MAX >> 5), // 00000111
+};
+
+bool match(const uint8_t&, CodeUnitType&&);
+void write(char32_t&, const uint8_t&, CodePoint&&, const uint8_t&);
+
+}
+}
+
+#endif // CODEPOINT_ITERATOR_UTILITY_H_