2012-09-25 17:22:28 +02:00
|
|
|
/*
|
2014-07-11 22:10:58 +02:00
|
|
|
* Copyright © 2011,2012,2014 Google, Inc.
|
2012-09-25 17:22:28 +02:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#ifndef HB_UTF_HH
|
|
|
|
#define HB_UTF_HH
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb.hh"
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2018-10-17 04:04:48 +02:00
|
|
|
#include "hb-open-type.hh"
|
|
|
|
|
2014-07-16 20:49:55 +02:00
|
|
|
|
2015-01-26 23:25:52 +01:00
|
|
|
struct hb_utf8_t
|
2012-09-25 17:22:28 +02:00
|
|
|
{
|
2015-01-26 23:25:52 +01:00
|
|
|
typedef uint8_t codepoint_t;
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-17 04:04:48 +02:00
|
|
|
next (const codepoint_t *text,
|
|
|
|
const codepoint_t *end,
|
2014-07-16 21:34:20 +02:00
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement)
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
|
|
|
/* Written to only accept well-formed sequences.
|
|
|
|
* Based on ideas from ICU's U8_NEXT.
|
2014-07-17 02:15:45 +02:00
|
|
|
* Generates one "replacement" for each ill-formed byte. */
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2014-07-16 20:49:55 +02:00
|
|
|
hb_codepoint_t c = *text++;
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2014-07-16 20:49:55 +02:00
|
|
|
if (c > 0x7Fu)
|
2014-07-11 22:10:58 +02:00
|
|
|
{
|
2017-06-19 12:17:09 +02:00
|
|
|
if (hb_in_range<hb_codepoint_t> (c, 0xC2u, 0xDFu)) /* Two-byte */
|
2014-07-11 22:10:58 +02:00
|
|
|
{
|
2014-07-16 20:49:55 +02:00
|
|
|
unsigned int t1;
|
|
|
|
if (likely (text < end &&
|
|
|
|
(t1 = text[0] - 0x80u) <= 0x3Fu))
|
|
|
|
{
|
|
|
|
c = ((c&0x1Fu)<<6) | t1;
|
|
|
|
text++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto error;
|
2014-07-11 22:10:58 +02:00
|
|
|
}
|
2017-06-19 12:17:09 +02:00
|
|
|
else if (hb_in_range<hb_codepoint_t> (c, 0xE0u, 0xEFu)) /* Three-byte */
|
2012-09-25 17:22:28 +02:00
|
|
|
{
|
2014-07-16 20:49:55 +02:00
|
|
|
unsigned int t1, t2;
|
|
|
|
if (likely (1 < end - text &&
|
|
|
|
(t1 = text[0] - 0x80u) <= 0x3Fu &&
|
|
|
|
(t2 = text[1] - 0x80u) <= 0x3Fu))
|
|
|
|
{
|
|
|
|
c = ((c&0xFu)<<12) | (t1<<6) | t2;
|
2017-06-19 12:17:09 +02:00
|
|
|
if (unlikely (c < 0x0800u || hb_in_range<hb_codepoint_t> (c, 0xD800u, 0xDFFFu)))
|
2014-07-16 20:49:55 +02:00
|
|
|
goto error;
|
|
|
|
text += 2;
|
|
|
|
}
|
|
|
|
else
|
2014-07-11 22:20:28 +02:00
|
|
|
goto error;
|
2012-09-25 17:22:28 +02:00
|
|
|
}
|
2017-06-19 12:17:09 +02:00
|
|
|
else if (hb_in_range<hb_codepoint_t> (c, 0xF0u, 0xF4u)) /* Four-byte */
|
2014-07-11 22:10:58 +02:00
|
|
|
{
|
2014-07-16 20:49:55 +02:00
|
|
|
unsigned int t1, t2, t3;
|
|
|
|
if (likely (2 < end - text &&
|
|
|
|
(t1 = text[0] - 0x80u) <= 0x3Fu &&
|
|
|
|
(t2 = text[1] - 0x80u) <= 0x3Fu &&
|
|
|
|
(t3 = text[2] - 0x80u) <= 0x3Fu))
|
|
|
|
{
|
|
|
|
c = ((c&0x7u)<<18) | (t1<<12) | (t2<<6) | t3;
|
2017-06-19 12:17:09 +02:00
|
|
|
if (unlikely (!hb_in_range<hb_codepoint_t> (c, 0x10000u, 0x10FFFFu)))
|
2014-07-16 20:49:55 +02:00
|
|
|
goto error;
|
|
|
|
text += 3;
|
|
|
|
}
|
|
|
|
else
|
2014-07-11 22:20:28 +02:00
|
|
|
goto error;
|
2014-07-11 22:10:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
}
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2014-07-16 20:49:55 +02:00
|
|
|
*unicode = c;
|
|
|
|
return text;
|
2012-09-25 19:59:24 +02:00
|
|
|
|
2014-07-16 20:49:55 +02:00
|
|
|
error:
|
2014-07-16 21:34:20 +02:00
|
|
|
*unicode = replacement;
|
2012-09-25 19:59:24 +02:00
|
|
|
return text;
|
2014-07-16 20:49:55 +02:00
|
|
|
}
|
2014-07-11 19:58:36 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-17 04:04:48 +02:00
|
|
|
prev (const codepoint_t *text,
|
|
|
|
const codepoint_t *start,
|
2014-07-16 21:34:20 +02:00
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement)
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
2018-10-17 04:04:48 +02:00
|
|
|
const codepoint_t *end = text--;
|
2014-07-16 20:49:55 +02:00
|
|
|
while (start < text && (*text & 0xc0) == 0x80 && end - text < 4)
|
|
|
|
text--;
|
2012-09-25 19:59:24 +02:00
|
|
|
|
2014-07-16 21:34:20 +02:00
|
|
|
if (likely (next (text, end, unicode, replacement) == end))
|
2014-07-16 20:49:55 +02:00
|
|
|
return text;
|
2012-09-25 19:59:24 +02:00
|
|
|
|
2014-07-16 21:34:20 +02:00
|
|
|
*unicode = replacement;
|
2014-07-16 20:49:55 +02:00
|
|
|
return end - 1;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-17 04:04:48 +02:00
|
|
|
strlen (const codepoint_t *text)
|
2018-12-16 20:08:10 +01:00
|
|
|
{ return ::strlen ((const char *) text); }
|
2018-10-24 05:04:05 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-24 05:04:05 +02:00
|
|
|
encode_len (hb_codepoint_t unicode)
|
|
|
|
{
|
|
|
|
if (unicode < 0x0080u) return 1;
|
|
|
|
if (unicode < 0x0800u) return 2;
|
|
|
|
if (unicode < 0x10000u) return 3;
|
|
|
|
if (unicode < 0x110000u) return 4;
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static codepoint_t *
|
2018-10-24 05:04:05 +02:00
|
|
|
encode (codepoint_t *text,
|
|
|
|
const codepoint_t *end,
|
|
|
|
hb_codepoint_t unicode)
|
|
|
|
{
|
|
|
|
if (unlikely (unicode >= 0xD800u && (unicode <= 0xDFFFu || unicode > 0x10FFFFu)))
|
|
|
|
unicode = 0xFFFDu;
|
|
|
|
if (unicode < 0x0080u)
|
|
|
|
*text++ = unicode;
|
|
|
|
else if (unicode < 0x0800u)
|
|
|
|
{
|
|
|
|
if (end - text >= 2)
|
|
|
|
{
|
|
|
|
*text++ = 0xC0u + (0x1Fu & (unicode >> 6));
|
|
|
|
*text++ = 0x80u + (0x3Fu & (unicode ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (unicode < 0x10000u)
|
|
|
|
{
|
|
|
|
if (end - text >= 3)
|
|
|
|
{
|
|
|
|
*text++ = 0xE0u + (0x0Fu & (unicode >> 12));
|
|
|
|
*text++ = 0x80u + (0x3Fu & (unicode >> 6));
|
|
|
|
*text++ = 0x80u + (0x3Fu & (unicode ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (end - text >= 4)
|
|
|
|
{
|
|
|
|
*text++ = 0xF0u + (0x07u & (unicode >> 18));
|
|
|
|
*text++ = 0x80u + (0x3Fu & (unicode >> 12));
|
|
|
|
*text++ = 0x80u + (0x3Fu & (unicode >> 6));
|
|
|
|
*text++ = 0x80u + (0x3Fu & (unicode ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
2014-07-16 20:49:55 +02:00
|
|
|
};
|
2012-09-25 17:42:16 +02:00
|
|
|
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2018-10-17 04:04:48 +02:00
|
|
|
template <typename TCodepoint>
|
|
|
|
struct hb_utf16_xe_t
|
2012-09-25 17:22:28 +02:00
|
|
|
{
|
2018-10-17 04:04:48 +02:00
|
|
|
static_assert (sizeof (TCodepoint) == 2, "");
|
|
|
|
typedef TCodepoint codepoint_t;
|
2015-01-26 23:25:52 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-17 04:04:48 +02:00
|
|
|
next (const codepoint_t *text,
|
|
|
|
const codepoint_t *end,
|
2014-07-16 21:34:20 +02:00
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement)
|
2012-09-25 18:26:12 +02:00
|
|
|
{
|
2014-07-16 20:49:55 +02:00
|
|
|
hb_codepoint_t c = *text++;
|
|
|
|
|
2017-06-19 12:17:09 +02:00
|
|
|
if (likely (!hb_in_range<hb_codepoint_t> (c, 0xD800u, 0xDFFFu)))
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
|
|
|
*unicode = c;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2015-11-06 22:58:38 +01:00
|
|
|
if (likely (c <= 0xDBFFu && text < end))
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
|
|
|
/* High-surrogate in c */
|
2015-11-06 22:58:38 +01:00
|
|
|
hb_codepoint_t l = *text;
|
2017-06-19 12:17:09 +02:00
|
|
|
if (likely (hb_in_range<hb_codepoint_t> (l, 0xDC00u, 0xDFFFu)))
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
|
|
|
/* Low-surrogate in l */
|
|
|
|
*unicode = (c << 10) + l - ((0xD800u << 10) - 0x10000u + 0xDC00u);
|
|
|
|
text++;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lonely / out-of-order surrogate. */
|
2014-07-16 21:34:20 +02:00
|
|
|
*unicode = replacement;
|
2014-07-11 01:31:40 +02:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-17 04:04:48 +02:00
|
|
|
prev (const codepoint_t *text,
|
|
|
|
const codepoint_t *start,
|
2014-07-16 21:34:20 +02:00
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement)
|
2014-07-11 01:31:40 +02:00
|
|
|
{
|
2015-11-06 23:00:04 +01:00
|
|
|
hb_codepoint_t c = *--text;
|
2014-07-16 20:49:55 +02:00
|
|
|
|
2017-06-19 12:17:09 +02:00
|
|
|
if (likely (!hb_in_range<hb_codepoint_t> (c, 0xD800u, 0xDFFFu)))
|
2012-09-25 18:26:12 +02:00
|
|
|
{
|
2014-07-16 20:49:55 +02:00
|
|
|
*unicode = c;
|
|
|
|
return text;
|
2014-07-11 01:31:40 +02:00
|
|
|
}
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2015-11-06 23:00:04 +01:00
|
|
|
if (likely (c >= 0xDC00u && start < text))
|
|
|
|
{
|
|
|
|
/* Low-surrogate in c */
|
|
|
|
hb_codepoint_t h = text[-1];
|
2017-06-19 12:17:09 +02:00
|
|
|
if (likely (hb_in_range<hb_codepoint_t> (h, 0xD800u, 0xDBFFu)))
|
2015-11-06 23:00:04 +01:00
|
|
|
{
|
2019-08-24 15:27:14 +02:00
|
|
|
/* High-surrogate in h */
|
|
|
|
*unicode = (h << 10) + c - ((0xD800u << 10) - 0x10000u + 0xDC00u);
|
|
|
|
text--;
|
|
|
|
return text;
|
2015-11-06 23:00:04 +01:00
|
|
|
}
|
|
|
|
}
|
2012-09-25 19:59:24 +02:00
|
|
|
|
2015-11-06 23:00:04 +01:00
|
|
|
/* Lonely / out-of-order surrogate. */
|
2014-07-16 21:34:20 +02:00
|
|
|
*unicode = replacement;
|
2015-11-06 23:00:04 +01:00
|
|
|
return text;
|
2014-07-11 01:31:40 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 21:10:05 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-17 04:04:48 +02:00
|
|
|
strlen (const codepoint_t *text)
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
|
|
|
unsigned int l = 0;
|
|
|
|
while (*text++) l++;
|
|
|
|
return l;
|
|
|
|
}
|
2018-10-24 05:04:05 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-24 05:04:05 +02:00
|
|
|
encode_len (hb_codepoint_t unicode)
|
|
|
|
{
|
|
|
|
return unicode < 0x10000 ? 1 : 2;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static codepoint_t *
|
2018-10-24 05:04:05 +02:00
|
|
|
encode (codepoint_t *text,
|
|
|
|
const codepoint_t *end,
|
|
|
|
hb_codepoint_t unicode)
|
|
|
|
{
|
|
|
|
if (unlikely (unicode >= 0xD800u && (unicode <= 0xDFFFu || unicode > 0x10FFFFu)))
|
|
|
|
unicode = 0xFFFDu;
|
|
|
|
if (unicode < 0x10000u)
|
|
|
|
*text++ = unicode;
|
|
|
|
else if (end - text >= 2)
|
|
|
|
{
|
|
|
|
unicode -= 0x10000u;
|
|
|
|
*text++ = 0xD800u + (unicode >> 10);
|
|
|
|
*text++ = 0xDC00u + (unicode & 0x03FFu);
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
2014-07-16 20:49:55 +02:00
|
|
|
};
|
2012-09-25 19:59:24 +02:00
|
|
|
|
2018-10-17 04:04:48 +02:00
|
|
|
typedef hb_utf16_xe_t<uint16_t> hb_utf16_t;
|
|
|
|
typedef hb_utf16_xe_t<OT::HBUINT16> hb_utf16_be_t;
|
|
|
|
|
2012-09-25 19:59:24 +02:00
|
|
|
|
2018-10-17 04:04:48 +02:00
|
|
|
template <typename TCodepoint, bool validate=true>
|
|
|
|
struct hb_utf32_xe_t
|
2012-09-25 17:42:16 +02:00
|
|
|
{
|
2018-10-17 04:04:48 +02:00
|
|
|
static_assert (sizeof (TCodepoint) == 4, "");
|
|
|
|
typedef TCodepoint codepoint_t;
|
2015-01-26 23:25:52 +01:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const TCodepoint *
|
2018-10-17 04:04:48 +02:00
|
|
|
next (const TCodepoint *text,
|
|
|
|
const TCodepoint *end HB_UNUSED,
|
2014-07-16 21:34:20 +02:00
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement)
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
2015-11-06 22:58:38 +01:00
|
|
|
hb_codepoint_t c = *unicode = *text++;
|
|
|
|
if (validate && unlikely (c >= 0xD800u && (c <= 0xDFFFu || c > 0x10FFFFu)))
|
|
|
|
*unicode = replacement;
|
2014-07-16 20:49:55 +02:00
|
|
|
return text;
|
|
|
|
}
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const TCodepoint *
|
2018-10-17 04:04:48 +02:00
|
|
|
prev (const TCodepoint *text,
|
|
|
|
const TCodepoint *start HB_UNUSED,
|
2014-07-16 21:34:20 +02:00
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement)
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
2015-11-06 23:00:04 +01:00
|
|
|
hb_codepoint_t c = *unicode = *--text;
|
|
|
|
if (validate && unlikely (c >= 0xD800u && (c <= 0xDFFFu || c > 0x10FFFFu)))
|
|
|
|
*unicode = replacement;
|
|
|
|
return text;
|
2014-07-16 20:49:55 +02:00
|
|
|
}
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-17 04:04:48 +02:00
|
|
|
strlen (const TCodepoint *text)
|
2014-07-16 20:49:55 +02:00
|
|
|
{
|
|
|
|
unsigned int l = 0;
|
|
|
|
while (*text++) l++;
|
|
|
|
return l;
|
|
|
|
}
|
2018-10-24 05:04:05 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-24 05:04:05 +02:00
|
|
|
encode_len (hb_codepoint_t unicode HB_UNUSED)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static codepoint_t *
|
2018-10-24 05:04:05 +02:00
|
|
|
encode (codepoint_t *text,
|
|
|
|
const codepoint_t *end HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode)
|
|
|
|
{
|
|
|
|
if (validate && unlikely (unicode >= 0xD800u && (unicode <= 0xDFFFu || unicode > 0x10FFFFu)))
|
|
|
|
unicode = 0xFFFDu;
|
|
|
|
*text++ = unicode;
|
|
|
|
return text;
|
|
|
|
}
|
2014-07-16 20:49:55 +02:00
|
|
|
};
|
2012-09-25 17:42:16 +02:00
|
|
|
|
2018-10-17 04:04:48 +02:00
|
|
|
typedef hb_utf32_xe_t<uint32_t> hb_utf32_t;
|
|
|
|
typedef hb_utf32_xe_t<uint32_t, false> hb_utf32_novalidate_t;
|
|
|
|
|
2012-09-25 17:22:28 +02:00
|
|
|
|
2015-01-26 23:25:52 +01:00
|
|
|
struct hb_latin1_t
|
|
|
|
{
|
|
|
|
typedef uint8_t codepoint_t;
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-17 04:04:48 +02:00
|
|
|
next (const codepoint_t *text,
|
|
|
|
const codepoint_t *end HB_UNUSED,
|
2015-01-26 23:25:52 +01:00
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement HB_UNUSED)
|
|
|
|
{
|
|
|
|
*unicode = *text++;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-17 04:04:48 +02:00
|
|
|
prev (const codepoint_t *text,
|
|
|
|
const codepoint_t *start HB_UNUSED,
|
2015-01-26 23:25:52 +01:00
|
|
|
hb_codepoint_t *unicode,
|
2018-10-27 06:01:11 +02:00
|
|
|
hb_codepoint_t replacement HB_UNUSED)
|
2015-01-26 23:25:52 +01:00
|
|
|
{
|
|
|
|
*unicode = *--text;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-17 04:04:48 +02:00
|
|
|
strlen (const codepoint_t *text)
|
2015-01-26 23:25:52 +01:00
|
|
|
{
|
|
|
|
unsigned int l = 0;
|
|
|
|
while (*text++) l++;
|
|
|
|
return l;
|
|
|
|
}
|
2018-10-24 05:04:05 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-24 05:04:05 +02:00
|
|
|
encode_len (hb_codepoint_t unicode HB_UNUSED)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static codepoint_t *
|
2018-10-24 05:04:05 +02:00
|
|
|
encode (codepoint_t *text,
|
|
|
|
const codepoint_t *end HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode)
|
|
|
|
{
|
|
|
|
if (unlikely (unicode >= 0x0100u))
|
|
|
|
unicode = '?';
|
|
|
|
*text++ = unicode;
|
|
|
|
return text;
|
|
|
|
}
|
2015-01-26 23:25:52 +01:00
|
|
|
};
|
|
|
|
|
2018-10-24 05:51:53 +02:00
|
|
|
|
|
|
|
struct hb_ascii_t
|
|
|
|
{
|
|
|
|
typedef uint8_t codepoint_t;
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-24 05:51:53 +02:00
|
|
|
next (const codepoint_t *text,
|
|
|
|
const codepoint_t *end HB_UNUSED,
|
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement HB_UNUSED)
|
|
|
|
{
|
|
|
|
*unicode = *text++;
|
2018-10-24 21:34:03 +02:00
|
|
|
if (*unicode >= 0x0080u)
|
2018-10-24 05:51:53 +02:00
|
|
|
*unicode = replacement;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static const codepoint_t *
|
2018-10-24 05:51:53 +02:00
|
|
|
prev (const codepoint_t *text,
|
|
|
|
const codepoint_t *start HB_UNUSED,
|
|
|
|
hb_codepoint_t *unicode,
|
|
|
|
hb_codepoint_t replacement)
|
|
|
|
{
|
|
|
|
*unicode = *--text;
|
2018-10-24 21:34:03 +02:00
|
|
|
if (*unicode >= 0x0080u)
|
2018-10-24 05:51:53 +02:00
|
|
|
*unicode = replacement;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-24 05:51:53 +02:00
|
|
|
strlen (const codepoint_t *text)
|
|
|
|
{
|
|
|
|
unsigned int l = 0;
|
|
|
|
while (*text++) l++;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static unsigned int
|
2018-10-24 05:51:53 +02:00
|
|
|
encode_len (hb_codepoint_t unicode HB_UNUSED)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static codepoint_t *
|
2018-10-24 05:51:53 +02:00
|
|
|
encode (codepoint_t *text,
|
|
|
|
const codepoint_t *end HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode)
|
|
|
|
{
|
|
|
|
if (unlikely (unicode >= 0x0080u))
|
|
|
|
unicode = '?';
|
|
|
|
*text++ = unicode;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#endif /* HB_UTF_HH */
|