Blame iconvdata/jisx0213.h

Packit 6c4009
/* Functions for JISX0213 conversion.
Packit 6c4009
   Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Bruno Haible <bruno@clisp.org>, 2002.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _JISX0213_H
Packit 6c4009
#define _JISX0213_H	1
Packit 6c4009
Packit 6c4009
#include <stdint.h>
Packit 6c4009
Packit 6c4009
extern const uint16_t __jisx0213_to_ucs_combining[][2];
Packit 6c4009
extern const uint16_t __jisx0213_to_ucs_main[120 * 94];
Packit 6c4009
extern const uint32_t __jisx0213_to_ucs_pagestart[];
Packit 6c4009
extern const int16_t __jisx0213_from_ucs_level1[2715];
Packit 6c4009
extern const uint16_t __jisx0213_from_ucs_level2[];
Packit 6c4009
Packit 6c4009
#define NELEMS(arr) (sizeof (arr) / sizeof (arr[0]))
Packit 6c4009
Packit 6c4009
static inline uint32_t
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
jisx0213_to_ucs4 (unsigned int row, unsigned int col)
Packit 6c4009
{
Packit 6c4009
  uint32_t val;
Packit 6c4009
Packit 6c4009
  if (row >= 0x121 && row <= 0x17e)
Packit 6c4009
    row -= 289;
Packit 6c4009
  else if (row == 0x221)
Packit 6c4009
    row -= 451;
Packit 6c4009
  else if (row >= 0x223 && row <= 0x225)
Packit 6c4009
    row -= 452;
Packit 6c4009
  else if (row == 0x228)
Packit 6c4009
    row -= 454;
Packit 6c4009
  else if (row >= 0x22c && row <= 0x22f)
Packit 6c4009
    row -= 457;
Packit 6c4009
  else if (row >= 0x26e && row <= 0x27e)
Packit 6c4009
    row -= 519;
Packit 6c4009
  else
Packit 6c4009
    return 0x0000;
Packit 6c4009
Packit 6c4009
  if (col >= 0x21 && col <= 0x7e)
Packit 6c4009
    col -= 0x21;
Packit 6c4009
  else
Packit 6c4009
    return 0x0000;
Packit 6c4009
Packit 6c4009
  val = __jisx0213_to_ucs_main[row * 94 + col];
Packit 6c4009
  val = __jisx0213_to_ucs_pagestart[val >> 8] + (val & 0xff);
Packit 6c4009
  if (val == 0xfffd)
Packit 6c4009
    val = 0x0000;
Packit 6c4009
  return val;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static inline uint16_t
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
ucs4_to_jisx0213 (uint32_t ucs)
Packit 6c4009
{
Packit 6c4009
  if (ucs < NELEMS (__jisx0213_from_ucs_level1) << 6)
Packit 6c4009
    {
Packit 6c4009
      int index1 = __jisx0213_from_ucs_level1[ucs >> 6];
Packit 6c4009
      if (index1 >= 0)
Packit 6c4009
	return __jisx0213_from_ucs_level2[(index1 << 6) + (ucs & 0x3f)];
Packit 6c4009
    }
Packit 6c4009
  return 0x0000;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static inline int
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
jisx0213_added_in_2004_p (uint16_t val)
Packit 6c4009
{
Packit 6c4009
  /* From JISX 0213:2000 to JISX 0213:2004, 10 characters were added to
Packit 6c4009
     plane 1, and plane 2 was left unchanged.  See ISO-IR-233.  */
Packit 6c4009
  switch (val >> 8)
Packit 6c4009
    {
Packit 6c4009
    case 0x2e:
Packit 6c4009
      return val == 0x2e21;
Packit 6c4009
    case 0x2f:
Packit 6c4009
      return val == 0x2f7e;
Packit 6c4009
    case 0x4f:
Packit 6c4009
      return val == 0x4f54 || val == 0x4f7e;
Packit 6c4009
    case 0x74:
Packit 6c4009
      return val == 0x7427;
Packit 6c4009
    case 0x7e:
Packit 6c4009
      return val >= 0x7e7a && val <= 0x7e7e;
Packit 6c4009
    default:
Packit 6c4009
      return 0;
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif /* _JISX0213_H */