Back to index

php5  5.3.10
mbfilter_iso8859_10.c
Go to the documentation of this file.
00001 /*
00002  * "streamable kanji code filter and converter"
00003  * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
00004  *
00005  * LICENSE NOTICES
00006  *
00007  * This file is part of "streamable kanji code filter and converter",
00008  * which is distributed under the terms of GNU Lesser General Public 
00009  * License (version 2) as published by the Free Software Foundation.
00010  *
00011  * This software 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
00014  * GNU 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 "streamable kanji code filter and converter";
00018  * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
00019  * Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * The author of this file:
00022  *
00023  */
00024 /*
00025  * The source code included in this files was separated from mbfilter.c
00026  * by moriyoshi koizumi <moriyoshi@php.net> on 4 dec 2002.
00027  * 
00028  */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include "config.h"
00032 #endif
00033 
00034 #include "mbfilter.h"
00035 #include "mbfilter_iso8859_10.h"
00036 #include "unicode_table_iso8859_10.h"
00037 
00038 static const char *mbfl_encoding_8859_10_aliases[] = {"ISO_8859-10", "latin6", NULL};
00039 
00040 const mbfl_encoding mbfl_encoding_8859_10 = {
00041        mbfl_no_encoding_8859_10,
00042        "ISO-8859-10",
00043        "ISO-8859-10",
00044        (const char *(*)[])&mbfl_encoding_8859_10_aliases,
00045        NULL,
00046        MBFL_ENCTYPE_SBCS
00047 };
00048 
00049 const struct mbfl_identify_vtbl vtbl_identify_8859_10 = {
00050        mbfl_no_encoding_8859_10,
00051        mbfl_filt_ident_common_ctor,
00052        mbfl_filt_ident_common_dtor,
00053        mbfl_filt_ident_true
00054 };
00055 
00056 const struct mbfl_convert_vtbl vtbl_8859_10_wchar = {
00057        mbfl_no_encoding_8859_10,
00058        mbfl_no_encoding_wchar,
00059        mbfl_filt_conv_common_ctor,
00060        mbfl_filt_conv_common_dtor,
00061        mbfl_filt_conv_8859_10_wchar,
00062        mbfl_filt_conv_common_flush
00063 };
00064 
00065 const struct mbfl_convert_vtbl vtbl_wchar_8859_10 = {
00066        mbfl_no_encoding_wchar,
00067        mbfl_no_encoding_8859_10,
00068        mbfl_filt_conv_common_ctor,
00069        mbfl_filt_conv_common_dtor,
00070        mbfl_filt_conv_wchar_8859_10,
00071        mbfl_filt_conv_common_flush
00072 };
00073 
00074 #define CK(statement)       do { if ((statement) < 0) return (-1); } while (0)
00075 
00076 /*
00077  * ISO-8859-10 => wchar
00078  */
00079 int mbfl_filt_conv_8859_10_wchar(int c, mbfl_convert_filter *filter)
00080 {
00081        int s;
00082 
00083        if (c >= 0 && c < 0xa0) {
00084               s = c;
00085        } else if (c >= 0xa0 && c < 0x100) {
00086               s = iso8859_10_ucs_table[c - 0xa0];
00087               if (s <= 0) {
00088                      s = c;
00089                      s &= MBFL_WCSPLANE_MASK;
00090                      s |= MBFL_WCSPLANE_8859_10;
00091               }
00092        } else {
00093               s = c;
00094               s &= MBFL_WCSGROUP_MASK;
00095               s |= MBFL_WCSGROUP_THROUGH;
00096        }
00097 
00098        CK((*filter->output_function)(s, filter->data));
00099 
00100        return c;
00101 }
00102 
00103 /*
00104  * wchar => ISO-8859-10
00105  */
00106 int mbfl_filt_conv_wchar_8859_10(int c, mbfl_convert_filter *filter)
00107 {
00108        int s, n;
00109 
00110        if (c >= 0 && c < 0xa0) {
00111               s = c;
00112        } else {
00113               s = -1;
00114               n = 95;
00115               while (n >= 0) {
00116                      if (c == iso8859_10_ucs_table[n]) {
00117                             s = 0xa0 + n;
00118                             break;
00119                      }
00120                      n--;
00121               }
00122               if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_8859_10) {
00123                      s = c & MBFL_WCSPLANE_MASK;
00124               }
00125        }
00126 
00127        if (s >= 0) {
00128               CK((*filter->output_function)(s, filter->data));
00129        } else {
00130               if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
00131                      CK(mbfl_filt_conv_illegal_output(c, filter));
00132               }
00133        }
00134 
00135        return c;
00136 }
00137 
00138