Blame iconvdata/jis0212.h

Packit Service 82fcde
/* Access functions for JISX0212 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 _JIS0212_H
Packit Service 82fcde
#define _JIS0212_H	1
Packit Service 82fcde
Packit Service 82fcde
#include <assert.h>
Packit Service 82fcde
#include <gconv.h>
Packit Service 82fcde
#include <stdint.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Struct for table with indeces in mapping table.  */
Packit Service 82fcde
struct jisx0212_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
/* Conversion table.  */
Packit Service 82fcde
extern const struct jisx0212_idx __jisx0212_to_ucs_idx[];
Packit Service 82fcde
extern const uint16_t __jisx0212_to_ucs[];
Packit Service 82fcde
Packit Service 82fcde
extern const struct jisx0212_idx __jisx0212_from_ucs_idx[];
Packit Service 82fcde
extern const char __jisx0212_from_ucs[][2];
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
static inline uint32_t
Packit Service 82fcde
__attribute ((always_inline))
Packit Service 82fcde
jisx0212_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
Packit Service 82fcde
{
Packit Service 82fcde
  const struct jisx0212_idx *rp = __jisx0212_to_ucs_idx;
Packit Service 82fcde
  unsigned char ch = *(*s);
Packit Service 82fcde
  unsigned char ch2;
Packit Service 82fcde
  uint32_t wch = 0;
Packit Service 82fcde
  int idx;
Packit Service 82fcde
Packit Service 82fcde
  if (ch < offset || (ch - offset) < 0x22 || (ch - offset) > 0x6d)
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 - offset - 0x21) * 94 + (ch2 - offset - 0x21);
Packit Service 82fcde
Packit Service 82fcde
  while (idx > rp->end)
Packit Service 82fcde
    ++rp;
Packit Service 82fcde
  if (idx >= rp->start)
Packit Service 82fcde
    wch = __jisx0212_to_ucs[rp->idx + idx - rp->start];
Packit Service 82fcde
Packit Service 82fcde
  if (wch != L'\0')
Packit Service 82fcde
    (*s) += 2;
Packit Service 82fcde
  else
Packit Service 82fcde
    wch = __UNKNOWN_10646_CHAR;
Packit Service 82fcde
Packit Service 82fcde
  return wch;
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_jisx0212 (uint32_t wch, unsigned char *s, size_t avail)
Packit Service 82fcde
{
Packit Service 82fcde
  const struct jisx0212_idx *rp = __jisx0212_from_ucs_idx;
Packit Service 82fcde
  unsigned int ch = (unsigned int) wch;
Packit Service 82fcde
  const char *cp;
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 = __jisx0212_from_ucs[rp->idx + ch - rp->start];
Packit Service 82fcde
  else
Packit Service 82fcde
    return __UNKNOWN_10646_CHAR;
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
  assert (cp[1] != '\0');
Packit Service 82fcde
  if (avail < 2)
Packit Service 82fcde
    return 0;
Packit Service 82fcde
Packit Service 82fcde
  s[1] = cp[1];
Packit Service 82fcde
  return 2;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#endif /* jis0212.h */