Blame iconvdata/jis0208.h

Packit Service 82fcde
/* Access functions for JISX0208 conversion.
Packit Service 82fcde
   Copyright (C) 1997-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>, 1997.
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 _JIS0208_H
Packit Service 82fcde
#define _JIS0208_H	1
Packit Service 82fcde
Packit Service 82fcde
#include <gconv.h>
Packit Service 82fcde
#include <stdint.h>
Packit Service 82fcde
Packit Service 82fcde
/* Struct for table with indeces in UCS mapping table.  */
Packit Service 82fcde
struct jisx0208_ucs_idx
Packit Service 82fcde
{
Packit Service 82fcde
  uint16_t start;
Packit Service 82fcde
  uint16_t end;
Packit Service 82fcde
  uint16_t idx;
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Conversion table.  */
Packit Service 82fcde
extern const uint16_t __jis0208_to_ucs[];
Packit Service 82fcde
Packit Service 82fcde
#define JIS0208_LAT1_MIN 0xa2
Packit Service 82fcde
#define JIS0208_LAT1_MAX 0xf7
Packit Service 82fcde
extern const char __jisx0208_from_ucs4_lat1[JIS0208_LAT1_MAX + 1
Packit Service 82fcde
					    - JIS0208_LAT1_MIN][2];
Packit Service 82fcde
extern const char __jisx0208_from_ucs4_greek[0xc1][2];
Packit Service 82fcde
extern const struct jisx0208_ucs_idx __jisx0208_from_ucs_idx[];
Packit Service 82fcde
extern const char __jisx0208_from_ucs_tab[][2];
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
static inline uint32_t
Packit Service 82fcde
__attribute ((always_inline))
Packit Service 82fcde
jisx0208_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
Packit Service 82fcde
{
Packit Service 82fcde
  unsigned char ch = *(*s);
Packit Service 82fcde
  unsigned char ch2;
Packit Service 82fcde
  int idx;
Packit Service 82fcde
Packit Service 82fcde
  if (ch < offset || (ch - offset) <= 0x20)
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 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  idx = (ch - 0x21 - offset) * 94 + (ch2 - 0x21 - offset);
Packit Service 82fcde
  if (idx >= 0x1e80)
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  (*s) += 2;
Packit Service 82fcde
Packit Service 82fcde
  return __jis0208_to_ucs[idx] ?: ((*s) -= 2, __UNKNOWN_10646_CHAR);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
static inline size_t
Packit Service 82fcde
__attribute ((always_inline))
Packit Service 82fcde
ucs4_to_jisx0208 (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
Packit Service 82fcde
  if (avail < 2)
Packit Service 82fcde
    return 0;
Packit Service 82fcde
Packit Service 82fcde
  if (ch >= JIS0208_LAT1_MIN && ch <= JIS0208_LAT1_MAX)
Packit Service 82fcde
    cp = __jisx0208_from_ucs4_lat1[ch - JIS0208_LAT1_MIN];
Packit Service 82fcde
  else if (ch >= 0x391 && ch <= 0x451)
Packit Service 82fcde
    cp = __jisx0208_from_ucs4_greek[ch - 0x391];
Packit Service 82fcde
  else
Packit Service 82fcde
    {
Packit Service 82fcde
      const struct jisx0208_ucs_idx *rp = __jisx0208_from_ucs_idx;
Packit Service 82fcde
Packit Service 82fcde
      if (ch >= 0xffff)
Packit Service 82fcde
	return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
      while (ch > rp->end)
Packit Service 82fcde
	++rp;
Packit Service 82fcde
      if (ch >= rp->start)
Packit Service 82fcde
	cp = __jisx0208_from_ucs_tab[rp->idx + ch - rp->start];
Packit Service 82fcde
      else
Packit Service 82fcde
	return __UNKNOWN_10646_CHAR;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  if (cp[0] == '\0')
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
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 /* jis0208.h */