Blame iconvdata/cns11643l2.h

Packit 6c4009
/* Access functions for CNS 11643, plane 2 handling.
Packit 6c4009
   Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
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
#include <stdint.h>
Packit 6c4009
#include <gconv.h>
Packit 6c4009
Packit 6c4009
/* Table for CNS 11643, plane 2 to UCS4 conversion.  */
Packit 6c4009
extern const uint16_t __cns11643l2_to_ucs4_tab[];
Packit 6c4009
Packit 6c4009
Packit 6c4009
static inline uint32_t
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
cns11643l2_to_ucs4 (const unsigned char **s, size_t avail,
Packit 6c4009
		    unsigned char offset)
Packit 6c4009
{
Packit 6c4009
  unsigned char ch = *(*s);
Packit 6c4009
  unsigned char ch2;
Packit 6c4009
  int idx;
Packit 6c4009
Packit 6c4009
  if (ch < offset || (ch - offset) <= 0x20 || (ch - offset) > 0x7d)
Packit 6c4009
    return __UNKNOWN_10646_CHAR;
Packit 6c4009
Packit 6c4009
  if (avail < 2)
Packit 6c4009
    return 0;
Packit 6c4009
Packit 6c4009
  ch2 = (*s)[1];
Packit 6c4009
  if ((ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
Packit 6c4009
    return __UNKNOWN_10646_CHAR;
Packit 6c4009
Packit 6c4009
  idx = (ch - 0x21 - offset) * 94 + (ch2 - 0x21 - offset);
Packit 6c4009
  if (idx > 0x1de1)
Packit 6c4009
    return __UNKNOWN_10646_CHAR;
Packit 6c4009
Packit 6c4009
  (*s) += 2;
Packit 6c4009
Packit 6c4009
  return __cns11643l2_to_ucs4_tab[idx] ?: ((*s) -= 2, __UNKNOWN_10646_CHAR);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* The table which contains the CNS 11643 level 2 mappings.  */
Packit 6c4009
extern const char __cns11643_from_ucs4p0_tab[][3];
Packit 6c4009
Packit 6c4009
Packit 6c4009
static inline size_t
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
ucs4_to_cns11643l2 (uint32_t wch, unsigned char *s, size_t avail)
Packit 6c4009
{
Packit 6c4009
  unsigned int ch = (unsigned int) wch;
Packit 6c4009
  const char *cp = NULL;
Packit 6c4009
Packit 6c4009
  if (ch >= 0x4e07 && ch <= 0x9fa4)
Packit 6c4009
    {
Packit 6c4009
      cp = __cns11643_from_ucs4p0_tab[ch - 0x3400];
Packit 6c4009
      if (cp[0] == '\2')
Packit 6c4009
	++cp;
Packit 6c4009
      else
Packit 6c4009
	cp = NULL;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (cp == NULL)
Packit 6c4009
    return __UNKNOWN_10646_CHAR;
Packit 6c4009
Packit 6c4009
  if (avail < 2)
Packit 6c4009
    return 0;
Packit 6c4009
Packit 6c4009
  s[0] = cp[0];
Packit 6c4009
  s[1] = cp[1];
Packit 6c4009
Packit 6c4009
  return 2;
Packit 6c4009
}