From 8d304ef7f9094a71fabc3efd87b37a030c437adf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 16 Oct 2018 19:04:48 -0700 Subject: [PATCH] [utf] Add UTF16-BE and UTF32-BE --- src/hb-buffer.cc | 4 +-- src/hb-utf.hh | 80 ++++++++++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index ce9b053..f905c63 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -1665,7 +1665,7 @@ hb_buffer_add_utf32 (hb_buffer_t *buffer, unsigned int item_offset, int item_length) { - hb_buffer_add_utf > (buffer, text, text_length, item_offset, item_length); + hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length); } /** @@ -1726,7 +1726,7 @@ hb_buffer_add_codepoints (hb_buffer_t *buffer, unsigned int item_offset, int item_length) { - hb_buffer_add_utf > (buffer, text, text_length, item_offset, item_length); + hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length); } diff --git a/src/hb-utf.hh b/src/hb-utf.hh index eccb632..d8b7114 100644 --- a/src/hb-utf.hh +++ b/src/hb-utf.hh @@ -29,14 +29,16 @@ #include "hb.hh" +#include "hb-open-type.hh" + struct hb_utf8_t { typedef uint8_t codepoint_t; - static inline const uint8_t * - next (const uint8_t *text, - const uint8_t *end, + static inline const codepoint_t * + next (const codepoint_t *text, + const codepoint_t *end, hb_codepoint_t *unicode, hb_codepoint_t replacement) { @@ -103,13 +105,13 @@ struct hb_utf8_t return text; } - static inline const uint8_t * - prev (const uint8_t *text, - const uint8_t *start, + static inline const codepoint_t * + prev (const codepoint_t *text, + const codepoint_t *start, hb_codepoint_t *unicode, hb_codepoint_t replacement) { - const uint8_t *end = text--; + const codepoint_t *end = text--; while (start < text && (*text & 0xc0) == 0x80 && end - text < 4) text--; @@ -121,20 +123,22 @@ struct hb_utf8_t } static inline unsigned int - strlen (const uint8_t *text) + strlen (const codepoint_t *text) { return ::strlen ((const char *) text); } }; -struct hb_utf16_t +template +struct hb_utf16_xe_t { - typedef uint16_t codepoint_t; + static_assert (sizeof (TCodepoint) == 2, ""); + typedef TCodepoint codepoint_t; - static inline const uint16_t * - next (const uint16_t *text, - const uint16_t *end, + static inline const codepoint_t * + next (const codepoint_t *text, + const codepoint_t *end, hb_codepoint_t *unicode, hb_codepoint_t replacement) { @@ -164,9 +168,9 @@ struct hb_utf16_t return text; } - static inline const uint16_t * - prev (const uint16_t *text, - const uint16_t *start, + static inline const codepoint_t * + prev (const codepoint_t *text, + const codepoint_t *start, hb_codepoint_t *unicode, hb_codepoint_t replacement) { @@ -198,7 +202,7 @@ struct hb_utf16_t static inline unsigned int - strlen (const uint16_t *text) + strlen (const codepoint_t *text) { unsigned int l = 0; while (*text++) l++; @@ -206,15 +210,19 @@ struct hb_utf16_t } }; +typedef hb_utf16_xe_t hb_utf16_t; +typedef hb_utf16_xe_t hb_utf16_be_t; + -template -struct hb_utf32_t +template +struct hb_utf32_xe_t { - typedef uint32_t codepoint_t; + static_assert (sizeof (TCodepoint) == 4, ""); + typedef TCodepoint codepoint_t; - static inline const uint32_t * - next (const uint32_t *text, - const uint32_t *end HB_UNUSED, + static inline const TCodepoint * + next (const TCodepoint *text, + const TCodepoint *end HB_UNUSED, hb_codepoint_t *unicode, hb_codepoint_t replacement) { @@ -224,9 +232,9 @@ struct hb_utf32_t return text; } - static inline const uint32_t * - prev (const uint32_t *text, - const uint32_t *start HB_UNUSED, + static inline const TCodepoint * + prev (const TCodepoint *text, + const TCodepoint *start HB_UNUSED, hb_codepoint_t *unicode, hb_codepoint_t replacement) { @@ -237,7 +245,7 @@ struct hb_utf32_t } static inline unsigned int - strlen (const uint32_t *text) + strlen (const TCodepoint *text) { unsigned int l = 0; while (*text++) l++; @@ -245,14 +253,18 @@ struct hb_utf32_t } }; +typedef hb_utf32_xe_t hb_utf32_t; +typedef hb_utf32_xe_t hb_utf32_novalidate_t; +typedef hb_utf32_xe_t hb_utf32_be_t; + struct hb_latin1_t { typedef uint8_t codepoint_t; - static inline const uint8_t * - next (const uint8_t *text, - const uint8_t *end HB_UNUSED, + static inline const codepoint_t * + next (const codepoint_t *text, + const codepoint_t *end HB_UNUSED, hb_codepoint_t *unicode, hb_codepoint_t replacement HB_UNUSED) { @@ -260,9 +272,9 @@ struct hb_latin1_t return text; } - static inline const uint8_t * - prev (const uint8_t *text, - const uint8_t *start HB_UNUSED, + static inline const codepoint_t * + prev (const codepoint_t *text, + const codepoint_t *start HB_UNUSED, hb_codepoint_t *unicode, hb_codepoint_t replacement) { @@ -271,7 +283,7 @@ struct hb_latin1_t } static inline unsigned int - strlen (const uint8_t *text) + strlen (const codepoint_t *text) { unsigned int l = 0; while (*text++) l++; -- 2.7.4