[utf] Add UTF16-BE and UTF32-BE

This commit is contained in:
Behdad Esfahbod 2018-10-16 19:04:48 -07:00
parent a826a8730f
commit 8d304ef7f9
2 changed files with 48 additions and 36 deletions

View File

@ -1665,7 +1665,7 @@ hb_buffer_add_utf32 (hb_buffer_t *buffer,
unsigned int item_offset, unsigned int item_offset,
int item_length) int item_length)
{ {
hb_buffer_add_utf<hb_utf32_t<> > (buffer, text, text_length, item_offset, item_length); hb_buffer_add_utf<hb_utf32_t> (buffer, text, text_length, item_offset, item_length);
} }
/** /**
@ -1726,7 +1726,7 @@ hb_buffer_add_codepoints (hb_buffer_t *buffer,
unsigned int item_offset, unsigned int item_offset,
int item_length) int item_length)
{ {
hb_buffer_add_utf<hb_utf32_t<false> > (buffer, text, text_length, item_offset, item_length); hb_buffer_add_utf<hb_utf32_novalidate_t> (buffer, text, text_length, item_offset, item_length);
} }

View File

@ -29,14 +29,16 @@
#include "hb.hh" #include "hb.hh"
#include "hb-open-type.hh"
struct hb_utf8_t struct hb_utf8_t
{ {
typedef uint8_t codepoint_t; typedef uint8_t codepoint_t;
static inline const uint8_t * static inline const codepoint_t *
next (const uint8_t *text, next (const codepoint_t *text,
const uint8_t *end, const codepoint_t *end,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement) hb_codepoint_t replacement)
{ {
@ -103,13 +105,13 @@ struct hb_utf8_t
return text; return text;
} }
static inline const uint8_t * static inline const codepoint_t *
prev (const uint8_t *text, prev (const codepoint_t *text,
const uint8_t *start, const codepoint_t *start,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement) hb_codepoint_t replacement)
{ {
const uint8_t *end = text--; const codepoint_t *end = text--;
while (start < text && (*text & 0xc0) == 0x80 && end - text < 4) while (start < text && (*text & 0xc0) == 0x80 && end - text < 4)
text--; text--;
@ -121,20 +123,22 @@ struct hb_utf8_t
} }
static inline unsigned int static inline unsigned int
strlen (const uint8_t *text) strlen (const codepoint_t *text)
{ {
return ::strlen ((const char *) text); return ::strlen ((const char *) text);
} }
}; };
struct hb_utf16_t template <typename TCodepoint>
struct hb_utf16_xe_t
{ {
typedef uint16_t codepoint_t; static_assert (sizeof (TCodepoint) == 2, "");
typedef TCodepoint codepoint_t;
static inline const uint16_t * static inline const codepoint_t *
next (const uint16_t *text, next (const codepoint_t *text,
const uint16_t *end, const codepoint_t *end,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement) hb_codepoint_t replacement)
{ {
@ -164,9 +168,9 @@ struct hb_utf16_t
return text; return text;
} }
static inline const uint16_t * static inline const codepoint_t *
prev (const uint16_t *text, prev (const codepoint_t *text,
const uint16_t *start, const codepoint_t *start,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement) hb_codepoint_t replacement)
{ {
@ -198,7 +202,7 @@ struct hb_utf16_t
static inline unsigned int static inline unsigned int
strlen (const uint16_t *text) strlen (const codepoint_t *text)
{ {
unsigned int l = 0; unsigned int l = 0;
while (*text++) l++; while (*text++) l++;
@ -206,15 +210,19 @@ struct hb_utf16_t
} }
}; };
typedef hb_utf16_xe_t<uint16_t> hb_utf16_t;
typedef hb_utf16_xe_t<OT::HBUINT16> hb_utf16_be_t;
template <bool validate=true>
struct hb_utf32_t template <typename TCodepoint, bool validate=true>
struct hb_utf32_xe_t
{ {
typedef uint32_t codepoint_t; static_assert (sizeof (TCodepoint) == 4, "");
typedef TCodepoint codepoint_t;
static inline const uint32_t * static inline const TCodepoint *
next (const uint32_t *text, next (const TCodepoint *text,
const uint32_t *end HB_UNUSED, const TCodepoint *end HB_UNUSED,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement) hb_codepoint_t replacement)
{ {
@ -224,9 +232,9 @@ struct hb_utf32_t
return text; return text;
} }
static inline const uint32_t * static inline const TCodepoint *
prev (const uint32_t *text, prev (const TCodepoint *text,
const uint32_t *start HB_UNUSED, const TCodepoint *start HB_UNUSED,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement) hb_codepoint_t replacement)
{ {
@ -237,7 +245,7 @@ struct hb_utf32_t
} }
static inline unsigned int static inline unsigned int
strlen (const uint32_t *text) strlen (const TCodepoint *text)
{ {
unsigned int l = 0; unsigned int l = 0;
while (*text++) l++; while (*text++) l++;
@ -245,14 +253,18 @@ struct hb_utf32_t
} }
}; };
typedef hb_utf32_xe_t<uint32_t> hb_utf32_t;
typedef hb_utf32_xe_t<uint32_t, false> hb_utf32_novalidate_t;
typedef hb_utf32_xe_t<OT::HBUINT32> hb_utf32_be_t;
struct hb_latin1_t struct hb_latin1_t
{ {
typedef uint8_t codepoint_t; typedef uint8_t codepoint_t;
static inline const uint8_t * static inline const codepoint_t *
next (const uint8_t *text, next (const codepoint_t *text,
const uint8_t *end HB_UNUSED, const codepoint_t *end HB_UNUSED,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement HB_UNUSED) hb_codepoint_t replacement HB_UNUSED)
{ {
@ -260,9 +272,9 @@ struct hb_latin1_t
return text; return text;
} }
static inline const uint8_t * static inline const codepoint_t *
prev (const uint8_t *text, prev (const codepoint_t *text,
const uint8_t *start HB_UNUSED, const codepoint_t *start HB_UNUSED,
hb_codepoint_t *unicode, hb_codepoint_t *unicode,
hb_codepoint_t replacement) hb_codepoint_t replacement)
{ {
@ -271,7 +283,7 @@ struct hb_latin1_t
} }
static inline unsigned int static inline unsigned int
strlen (const uint8_t *text) strlen (const codepoint_t *text)
{ {
unsigned int l = 0; unsigned int l = 0;
while (*text++) l++; while (*text++) l++;