Back to index

glibc  2.9
jisx0213.h
Go to the documentation of this file.
00001 /* Functions for JISX0213 conversion.
00002    Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Bruno Haible <bruno@clisp.org>, 2002.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _JISX0213_H
00022 #define _JISX0213_H  1
00023 
00024 #include <stdint.h>
00025 
00026 extern const uint16_t __jisx0213_to_ucs_combining[][2];
00027 extern const uint16_t __jisx0213_to_ucs_main[120 * 94];
00028 extern const uint32_t __jisx0213_to_ucs_pagestart[];
00029 extern const int16_t __jisx0213_from_ucs_level1[2715];
00030 extern const uint16_t __jisx0213_from_ucs_level2[];
00031 
00032 #define NELEMS(arr) (sizeof (arr) / sizeof (arr[0]))
00033 
00034 static inline uint32_t
00035 __attribute ((always_inline))
00036 jisx0213_to_ucs4 (unsigned int row, unsigned int col)
00037 {
00038   uint32_t val;
00039 
00040   if (row >= 0x121 && row <= 0x17e)
00041     row -= 289;
00042   else if (row == 0x221)
00043     row -= 451;
00044   else if (row >= 0x223 && row <= 0x225)
00045     row -= 452;
00046   else if (row == 0x228)
00047     row -= 454;
00048   else if (row >= 0x22c && row <= 0x22f)
00049     row -= 457;
00050   else if (row >= 0x26e && row <= 0x27e)
00051     row -= 519;
00052   else
00053     return 0x0000;
00054 
00055   if (col >= 0x21 && col <= 0x7e)
00056     col -= 0x21;
00057   else
00058     return 0x0000;
00059 
00060   val = __jisx0213_to_ucs_main[row * 94 + col];
00061   val = __jisx0213_to_ucs_pagestart[val >> 8] + (val & 0xff);
00062   if (val == 0xfffd)
00063     val = 0x0000;
00064   return val;
00065 }
00066 
00067 static inline uint16_t
00068 __attribute ((always_inline))
00069 ucs4_to_jisx0213 (uint32_t ucs)
00070 {
00071   if (ucs < NELEMS (__jisx0213_from_ucs_level1) << 6)
00072     {
00073       int index1 = __jisx0213_from_ucs_level1[ucs >> 6];
00074       if (index1 >= 0)
00075        return __jisx0213_from_ucs_level2[(index1 << 6) + (ucs & 0x3f)];
00076     }
00077   return 0x0000;
00078 }
00079 
00080 static inline int
00081 __attribute ((always_inline))
00082 jisx0213_added_in_2004_p (uint16_t val)
00083 {
00084   /* From JISX 0213:2000 to JISX 0213:2004, 10 characters were added to
00085      plane 1, and plane 2 was left unchanged.  See ISO-IR-233.  */
00086   switch (val >> 8)
00087     {
00088     case 0x2e:
00089       return val == 0x2e21;
00090     case 0x2f:
00091       return val == 0x2f7e;
00092     case 0x4f:
00093       return val == 0x4f54 || val == 0x4f7e;
00094     case 0x74:
00095       return val == 0x7427;
00096     case 0x7e:
00097       return val >= 0x7e7a && val <= 0x7e7e;
00098     default:
00099       return 0;
00100     }
00101 }
00102 
00103 #endif /* _JISX0213_H */