Back to index

php5  5.3.10
mbfl_language.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 20 Dec 2002. The file
00027  * mbfilter.c is included in this package .
00028  *
00029  */
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include "config.h"
00033 #endif
00034 
00035 #ifdef HAVE_STDDEF_H
00036 #include <stddef.h>
00037 #endif
00038 
00039 #ifdef HAVE_STDDEF_H
00040 #include <stddef.h>
00041 #endif
00042 
00043 #ifdef HAVE_STRING_H
00044 #include <string.h>
00045 #endif
00046 
00047 #ifdef HAVE_STRINGS_H
00048 #include <strings.h>
00049 #endif
00050 
00051 #include "mbfl_encoding.h"
00052 #include "mbfl_language.h"
00053 
00054 #include "nls/nls_ja.h"
00055 #include "nls/nls_kr.h"
00056 #include "nls/nls_zh.h"
00057 #include "nls/nls_uni.h"
00058 #include "nls/nls_de.h"
00059 #include "nls/nls_ru.h"
00060 #include "nls/nls_ua.h"
00061 #include "nls/nls_en.h"
00062 #include "nls/nls_hy.h"
00063 #include "nls/nls_tr.h"
00064 #include "nls/nls_neutral.h"
00065 
00066 #ifndef HAVE_STRCASECMP
00067 #ifdef HAVE_STRICMP
00068 #define strcasecmp stricmp
00069 #endif
00070 #endif 
00071 
00072 static const mbfl_language *mbfl_language_ptr_table[] = {
00073        &mbfl_language_uni,
00074        &mbfl_language_japanese,
00075        &mbfl_language_korean,
00076        &mbfl_language_simplified_chinese,
00077        &mbfl_language_traditional_chinese,
00078        &mbfl_language_english,
00079        &mbfl_language_german,
00080        &mbfl_language_russian,
00081        &mbfl_language_ukrainian,
00082        &mbfl_language_armenian,
00083        &mbfl_language_turkish,
00084        &mbfl_language_neutral,
00085        NULL
00086 };
00087 
00088 /* language resolver */
00089 const mbfl_language *
00090 mbfl_name2language(const char *name)
00091 {
00092        const mbfl_language *language;
00093        int i, j;
00094 
00095        if (name == NULL) {
00096               return NULL;
00097        }
00098 
00099        i = 0;
00100        while ((language = mbfl_language_ptr_table[i++]) != NULL){
00101               if (strcasecmp(language->name, name) == 0) {
00102                      return language;
00103               }
00104        }
00105 
00106        i = 0;
00107        while ((language = mbfl_language_ptr_table[i++]) != NULL){
00108               if (strcasecmp(language->short_name, name) == 0) {
00109                      return language;
00110               }
00111        }
00112 
00113        /* serch aliases */
00114        i = 0;
00115        while ((language = mbfl_language_ptr_table[i++]) != NULL) {
00116               if (language->aliases != NULL) {
00117                      j = 0;
00118                      while ((*language->aliases)[j] != NULL) {
00119                             if (strcasecmp((*language->aliases)[j], name) == 0) {
00120                                    return language;
00121                             }
00122                             j++;
00123                      }
00124               }
00125        }
00126 
00127        return NULL;
00128 }
00129 
00130 const mbfl_language *
00131 mbfl_no2language(enum mbfl_no_language no_language)
00132 {
00133        const mbfl_language *language;
00134        int i;
00135 
00136        i = 0;
00137        while ((language = mbfl_language_ptr_table[i++]) != NULL){
00138               if (language->no_language == no_language) {
00139                      return language;
00140               }
00141        }
00142 
00143        return NULL;
00144 }
00145 
00146 enum mbfl_no_language
00147 mbfl_name2no_language(const char *name)
00148 {
00149        const mbfl_language *language;
00150 
00151        language = mbfl_name2language(name);
00152        if (language == NULL) {
00153               return mbfl_no_language_invalid;
00154        } else {
00155               return language->no_language;
00156        }
00157 }
00158 
00159 const char *
00160 mbfl_no_language2name(enum mbfl_no_language no_language)
00161 {
00162        const mbfl_language *language;
00163 
00164        language = mbfl_no2language(no_language);
00165        if (language == NULL) {
00166               return "";
00167        } else {
00168               return language->name;
00169        }
00170 }
00171