Blame iconvdata/iso-ir-165.h

Packit Service 82fcde
/* Tables for conversion to and from ISO-IR-165.
Packit Service 82fcde
   converting from UCS using gaps.
Packit Service 82fcde
   Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef _ISO_IR_165_H
Packit Service 82fcde
#define _ISO_IR_165_H	1
Packit Service 82fcde
Packit Service 82fcde
#include <gconv.h>
Packit Service 82fcde
#include <stdint.h>
Packit Service 82fcde
Packit Service 82fcde
struct gap
Packit Service 82fcde
{
Packit Service 82fcde
  uint16_t start;
Packit Service 82fcde
  uint16_t end;
Packit Service 82fcde
  int32_t idx;
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
/* Table for ISO-IR-165 (CCITT Chinese) to UCS4 conversion.  */
Packit Service 82fcde
#define ISOIR165_FROMSIZE	0x2284
Packit Service 82fcde
extern const uint16_t __isoir165_to_tab[ISOIR165_FROMSIZE];
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* XXX If we at some point need an offset value to decode the byte
Packit Service 82fcde
   sequences another parameter can be added.  */
Packit Service 82fcde
static inline uint32_t
Packit Service 82fcde
__attribute ((always_inline))
Packit Service 82fcde
isoir165_to_ucs4 (const unsigned char **s, size_t avail)
Packit Service 82fcde
{
Packit Service 82fcde
  unsigned char ch = *(*s);
Packit Service 82fcde
  unsigned char ch2;
Packit Service 82fcde
  uint32_t res;
Packit Service 82fcde
Packit Service 82fcde
  if (ch <= 0x20 || ch >= 0x7f)
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  if (avail < 2)
Packit Service 82fcde
    return 0;
Packit Service 82fcde
Packit Service 82fcde
  ch2 = (*s)[1];
Packit Service 82fcde
  if (ch2 <= 0x20 || ch2 >= 0x7f)
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  res = __isoir165_to_tab[(ch - 0x21) * 94 + (ch2 - 0x21)];
Packit Service 82fcde
  if (res == 0)
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  *s += 2;
Packit Service 82fcde
  return res;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Tables for ISO-IR-165 (CCITT Chinese) from UCS4 conversion.  */
Packit Service 82fcde
extern const struct gap __isoir165_from_idx[];
Packit Service 82fcde
extern const char __isoir165_from_tab[];
Packit Service 82fcde
Packit Service 82fcde
static inline size_t
Packit Service 82fcde
__attribute ((always_inline))
Packit Service 82fcde
ucs4_to_isoir165 (uint32_t wch, unsigned char *s, size_t avail)
Packit Service 82fcde
{
Packit Service 82fcde
  unsigned int ch = (unsigned int) wch;
Packit Service 82fcde
  const char *cp;
Packit Service 82fcde
  const struct gap *rp = __isoir165_from_idx;
Packit Service 82fcde
Packit Service 82fcde
  if (ch > 0xffe5)
Packit Service 82fcde
    /* This is an illegal character.  */
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  while (ch > rp->end)
Packit Service 82fcde
    ++rp;
Packit Service 82fcde
  if (ch < rp->start)
Packit Service 82fcde
    /* This is an illegal character.  */
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  /* The two bytes following the index given in this record give the
Packit Service 82fcde
     encoding in ISO-IR-165.  Unless the bytes are zero.  */
Packit Service 82fcde
  cp = &__isoir165_from_tab[(ch + rp->idx) * 2];
Packit Service 82fcde
  if (*cp == '\0')
Packit Service 82fcde
    /* This is an illegal character.  */
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  if (avail < 2)
Packit Service 82fcde
    return 0;
Packit Service 82fcde
Packit Service 82fcde
  s[0] = cp[0];
Packit Service 82fcde
  s[1] = cp[1];
Packit Service 82fcde
Packit Service 82fcde
  return 2;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#endif	/* iso-ir-165.h */