Back to index

glibc  2.9
jis0201.h
Go to the documentation of this file.
00001 /* Access functions for JISX0201 conversion.
00002    Copyright (C) 1997, 1998, 1999, 2003, 2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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 _JIS0201_H
00022 #define _JIS0201_H   1
00023 
00024 /* Conversion table.  */
00025 extern const uint32_t __jisx0201_to_ucs4[];
00026 
00027 
00028 static inline uint32_t
00029 __attribute ((always_inline))
00030 jisx0201_to_ucs4 (char ch)
00031 {
00032   uint32_t val = __jisx0201_to_ucs4[(unsigned char) ch];
00033 
00034   if (val == 0 && ch != '\0')
00035     val = __UNKNOWN_10646_CHAR;
00036 
00037   return val;
00038 }
00039 
00040 
00041 static inline size_t
00042 __attribute ((always_inline))
00043 ucs4_to_jisx0201 (uint32_t wch, unsigned char *s)
00044 {
00045   unsigned char ch;
00046 
00047   if (wch == 0xa5)
00048     ch = '\x5c';
00049   else if (wch == 0x203e)
00050     ch = '\x7e';
00051   else if (wch < 0x7e && wch != 0x5c)
00052     ch = wch;
00053   else if (wch >= 0xff61 && wch <= 0xff9f)
00054     ch = wch - 0xfec0;
00055   else
00056     return __UNKNOWN_10646_CHAR;
00057 
00058   s[0] = ch;
00059   return 1;
00060 }
00061 
00062 #endif /* jis0201.h */