|
Packit |
6c4009 |
/* Tables for conversion to and from ISO-IR-165.
|
|
Packit |
6c4009 |
converting from UCS using gaps.
|
|
Packit |
6c4009 |
Copyright (C) 2000-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>, 2000.
|
|
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 _ISO_IR_165_H
|
|
Packit |
6c4009 |
#define _ISO_IR_165_H 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <gconv.h>
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct gap
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
uint16_t start;
|
|
Packit |
6c4009 |
uint16_t end;
|
|
Packit |
6c4009 |
int32_t idx;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Table for ISO-IR-165 (CCITT Chinese) to UCS4 conversion. */
|
|
Packit |
6c4009 |
#define ISOIR165_FROMSIZE 0x2284
|
|
Packit |
6c4009 |
extern const uint16_t __isoir165_to_tab[ISOIR165_FROMSIZE];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* XXX If we at some point need an offset value to decode the byte
|
|
Packit |
6c4009 |
sequences another parameter can be added. */
|
|
Packit |
6c4009 |
static inline uint32_t
|
|
Packit |
6c4009 |
__attribute ((always_inline))
|
|
Packit |
6c4009 |
isoir165_to_ucs4 (const unsigned char **s, size_t avail)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
unsigned char ch = *(*s);
|
|
Packit |
6c4009 |
unsigned char ch2;
|
|
Packit |
6c4009 |
uint32_t res;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (ch <= 0x20 || ch >= 0x7f)
|
|
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 <= 0x20 || ch2 >= 0x7f)
|
|
Packit |
6c4009 |
return __UNKNOWN_10646_CHAR;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
res = __isoir165_to_tab[(ch - 0x21) * 94 + (ch2 - 0x21)];
|
|
Packit |
6c4009 |
if (res == 0)
|
|
Packit |
6c4009 |
return __UNKNOWN_10646_CHAR;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
*s += 2;
|
|
Packit |
6c4009 |
return res;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Tables for ISO-IR-165 (CCITT Chinese) from UCS4 conversion. */
|
|
Packit |
6c4009 |
extern const struct gap __isoir165_from_idx[];
|
|
Packit |
6c4009 |
extern const char __isoir165_from_tab[];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static inline size_t
|
|
Packit |
6c4009 |
__attribute ((always_inline))
|
|
Packit |
6c4009 |
ucs4_to_isoir165 (uint32_t wch, unsigned char *s, size_t avail)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
unsigned int ch = (unsigned int) wch;
|
|
Packit |
6c4009 |
const char *cp;
|
|
Packit |
6c4009 |
const struct gap *rp = __isoir165_from_idx;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (ch > 0xffe5)
|
|
Packit |
6c4009 |
/* This is an illegal character. */
|
|
Packit |
6c4009 |
return __UNKNOWN_10646_CHAR;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
while (ch > rp->end)
|
|
Packit |
6c4009 |
++rp;
|
|
Packit |
6c4009 |
if (ch < rp->start)
|
|
Packit |
6c4009 |
/* This is an illegal character. */
|
|
Packit |
6c4009 |
return __UNKNOWN_10646_CHAR;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The two bytes following the index given in this record give the
|
|
Packit |
6c4009 |
encoding in ISO-IR-165. Unless the bytes are zero. */
|
|
Packit |
6c4009 |
cp = &__isoir165_from_tab[(ch + rp->idx) * 2];
|
|
Packit |
6c4009 |
if (*cp == '\0')
|
|
Packit |
6c4009 |
/* This is an illegal character. */
|
|
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 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* iso-ir-165.h */
|