[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,
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,
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-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 <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 *
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<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 *
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<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
{
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++;