Exemplo n.º 1
0
uint32_t
utf16_to_code_point_prev(const uint16_t *chars, size_t len, ssize_t *iter) {
  const uint16_t v = chars[(*iter)--];
  if (HB_IsLowSurrogate(v)) {
    // surrogate pair
    if (*iter < 0) {
      // the surrogate is incomplete.
      return HB_InvalidCodePoint;
    }
    const uint16_t v2 = chars[(*iter)--];
    if (!HB_IsHighSurrogate(v2)) {
      // invalidate surrogate pair.
      return HB_InvalidCodePoint;
    }

    return HB_SurrogateToUcs4(v2, v);
  }

  if (HB_IsHighSurrogate(v)) {
    // this isn't a valid code point
    return HB_InvalidCodePoint;
  }

  return v;
}
Exemplo n.º 2
0
static HB_UChar32 getChar(const HB_UChar16 *string, hb_uint32 length, hb_uint32 &i)
{
    HB_UChar32 ch;
    if (HB_IsHighSurrogate(string[i])
        && i < length - 1
        && HB_IsLowSurrogate(string[i + 1])) {
        ch = HB_SurrogateToUcs4(string[i], string[i + 1]);
        ++i;
    } else {
        ch = string[i];
    }
    return ch;
}