PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - mbstring/libmbfl/mbfl - mbfl_encoding.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 49
Code covered: 79.6 % Executed lines: 39
Legend: not executed executed

       1                 : /*
       2                 :  * "streamable kanji code filter and converter"
       3                 :  * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
       4                 :  *
       5                 :  * LICENSE NOTICES
       6                 :  *
       7                 :  * This file is part of "streamable kanji code filter and converter",
       8                 :  * which is distributed under the terms of GNU Lesser General Public 
       9                 :  * License (version 2) as published by the Free Software Foundation.
      10                 :  *
      11                 :  * This software is distributed in the hope that it will be useful,
      12                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :  * GNU Lesser General Public License for more details.
      15                 :  *
      16                 :  * You should have received a copy of the GNU Lesser General Public
      17                 :  * License along with "streamable kanji code filter and converter";
      18                 :  * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
      19                 :  * Suite 330, Boston, MA  02111-1307  USA
      20                 :  *
      21                 :  * The author of this file:
      22                 :  *
      23                 :  */
      24                 : /*
      25                 :  * The source code included in this files was separated from mbfilter.c
      26                 :  * by Moriyoshi Koizumi <moriyoshi@php.net> on 20 Dec 2002. The file
      27                 :  * mbfilter.c is included in this package .
      28                 :  *
      29                 :  */
      30                 : 
      31                 : #ifdef HAVE_CONFIG_H
      32                 : #include "config.h"
      33                 : #endif
      34                 : 
      35                 : #ifdef HAVE_STDDEF_H
      36                 : #include <stddef.h>
      37                 : #endif
      38                 : 
      39                 : #ifdef HAVE_STRING_H
      40                 : #include <string.h>
      41                 : #endif
      42                 : 
      43                 : #ifdef HAVE_STRINGS_H
      44                 : #include <strings.h>
      45                 : #endif
      46                 : 
      47                 : #include "mbfl_encoding.h"
      48                 : #include "mbfilter_pass.h"
      49                 : #include "mbfilter_8bit.h"
      50                 : #include "mbfilter_wchar.h"
      51                 : 
      52                 : #include "filters/mbfilter_euc_cn.h"
      53                 : #include "filters/mbfilter_hz.h"
      54                 : #include "filters/mbfilter_euc_tw.h"
      55                 : #include "filters/mbfilter_big5.h"
      56                 : #include "filters/mbfilter_uhc.h"
      57                 : #include "filters/mbfilter_euc_kr.h"
      58                 : #include "filters/mbfilter_iso2022_kr.h"
      59                 : #include "filters/mbfilter_sjis.h"
      60                 : #include "filters/mbfilter_cp51932.h"
      61                 : #include "filters/mbfilter_jis.h"
      62                 : #include "filters/mbfilter_iso2022_jp_ms.h"
      63                 : #include "filters/mbfilter_euc_jp.h"
      64                 : #include "filters/mbfilter_euc_jp_win.h"
      65                 : #include "filters/mbfilter_ascii.h"
      66                 : #include "filters/mbfilter_koi8r.h"
      67                 : #include "filters/mbfilter_cp866.h"
      68                 : #include "filters/mbfilter_cp932.h"
      69                 : #include "filters/mbfilter_cp936.h"
      70                 : #include "filters/mbfilter_cp1251.h"
      71                 : #include "filters/mbfilter_cp1252.h"
      72                 : #include "filters/mbfilter_iso8859_1.h"
      73                 : #include "filters/mbfilter_iso8859_2.h"
      74                 : #include "filters/mbfilter_iso8859_3.h"
      75                 : #include "filters/mbfilter_iso8859_4.h"
      76                 : #include "filters/mbfilter_iso8859_5.h"
      77                 : #include "filters/mbfilter_iso8859_6.h"
      78                 : #include "filters/mbfilter_iso8859_7.h"
      79                 : #include "filters/mbfilter_iso8859_8.h"
      80                 : #include "filters/mbfilter_iso8859_9.h"
      81                 : #include "filters/mbfilter_iso8859_10.h"
      82                 : #include "filters/mbfilter_iso8859_13.h"
      83                 : #include "filters/mbfilter_iso8859_14.h"
      84                 : #include "filters/mbfilter_iso8859_15.h"
      85                 : #include "filters/mbfilter_iso8859_16.h"
      86                 : #include "filters/mbfilter_base64.h"
      87                 : #include "filters/mbfilter_qprint.h"
      88                 : #include "filters/mbfilter_uuencode.h"
      89                 : #include "filters/mbfilter_7bit.h"
      90                 : #include "filters/mbfilter_utf7.h"
      91                 : #include "filters/mbfilter_utf7imap.h"
      92                 : #include "filters/mbfilter_utf8.h"
      93                 : #include "filters/mbfilter_utf16.h"
      94                 : #include "filters/mbfilter_utf32.h"
      95                 : #include "filters/mbfilter_byte2.h"
      96                 : #include "filters/mbfilter_byte4.h"
      97                 : #include "filters/mbfilter_ucs4.h"
      98                 : #include "filters/mbfilter_ucs2.h"
      99                 : #include "filters/mbfilter_htmlent.h"
     100                 : #include "filters/mbfilter_armscii8.h"
     101                 : 
     102                 : #ifndef HAVE_STRCASECMP
     103                 : #ifdef HAVE_STRICMP
     104                 : #define strcasecmp stricmp
     105                 : #endif
     106                 : #endif 
     107                 : 
     108                 : 
     109                 : static const char *mbfl_encoding_auto_aliases[] = {"unknown", NULL};
     110                 : 
     111                 : static const mbfl_encoding mbfl_encoding_auto = {
     112                 :         mbfl_no_encoding_auto,
     113                 :         "auto",
     114                 :         NULL,
     115                 :         (const char *(*)[])&mbfl_encoding_auto_aliases,
     116                 :         NULL,
     117                 :         0
     118                 : };
     119                 : 
     120                 : static const mbfl_encoding *mbfl_encoding_ptr_list[] = {
     121                 :         &mbfl_encoding_pass,
     122                 :         &mbfl_encoding_auto,
     123                 :         &mbfl_encoding_wchar,
     124                 :         &mbfl_encoding_byte2be,
     125                 :         &mbfl_encoding_byte2le,
     126                 :         &mbfl_encoding_byte4be,
     127                 :         &mbfl_encoding_byte4le,
     128                 :         &mbfl_encoding_base64,
     129                 :         &mbfl_encoding_uuencode,
     130                 :         &mbfl_encoding_html_ent,
     131                 :         &mbfl_encoding_qprint,
     132                 :         &mbfl_encoding_7bit,
     133                 :         &mbfl_encoding_8bit,
     134                 :         &mbfl_encoding_ucs4,
     135                 :         &mbfl_encoding_ucs4be,
     136                 :         &mbfl_encoding_ucs4le,
     137                 :         &mbfl_encoding_ucs2,
     138                 :         &mbfl_encoding_ucs2be,
     139                 :         &mbfl_encoding_ucs2le,
     140                 :         &mbfl_encoding_utf32,
     141                 :         &mbfl_encoding_utf32be,
     142                 :         &mbfl_encoding_utf32le,
     143                 :         &mbfl_encoding_utf16,
     144                 :         &mbfl_encoding_utf16be,
     145                 :         &mbfl_encoding_utf16le,
     146                 :         &mbfl_encoding_utf8,
     147                 :         &mbfl_encoding_utf7,
     148                 :         &mbfl_encoding_utf7imap,
     149                 :         &mbfl_encoding_ascii,
     150                 :         &mbfl_encoding_euc_jp,
     151                 :         &mbfl_encoding_sjis,
     152                 :         &mbfl_encoding_eucjp_win,
     153                 :         &mbfl_encoding_sjis_win,
     154                 :         &mbfl_encoding_cp51932,
     155                 :         &mbfl_encoding_jis,
     156                 :         &mbfl_encoding_2022jp,
     157                 :         &mbfl_encoding_2022jpms,
     158                 :         &mbfl_encoding_cp1252,
     159                 :         &mbfl_encoding_8859_1,
     160                 :         &mbfl_encoding_8859_2,
     161                 :         &mbfl_encoding_8859_3,
     162                 :         &mbfl_encoding_8859_4,
     163                 :         &mbfl_encoding_8859_5,
     164                 :         &mbfl_encoding_8859_6,
     165                 :         &mbfl_encoding_8859_7,
     166                 :         &mbfl_encoding_8859_8,
     167                 :         &mbfl_encoding_8859_9,
     168                 :         &mbfl_encoding_8859_10,
     169                 :         &mbfl_encoding_8859_13,
     170                 :         &mbfl_encoding_8859_14,
     171                 :         &mbfl_encoding_8859_15,
     172                 :         &mbfl_encoding_8859_16,
     173                 :         &mbfl_encoding_euc_cn,
     174                 :         &mbfl_encoding_cp936,
     175                 :         &mbfl_encoding_hz,
     176                 :         &mbfl_encoding_euc_tw,
     177                 :         &mbfl_encoding_big5,
     178                 :         &mbfl_encoding_euc_kr,
     179                 :         &mbfl_encoding_uhc,
     180                 :         &mbfl_encoding_2022kr,
     181                 :         &mbfl_encoding_cp1251,
     182                 :         &mbfl_encoding_cp866,
     183                 :         &mbfl_encoding_koi8r,
     184                 :         &mbfl_encoding_armscii8,
     185                 :         NULL
     186                 : };
     187                 : 
     188                 : /* encoding resolver */
     189                 : const mbfl_encoding *
     190                 : mbfl_name2encoding(const char *name)
     191          153262 : {
     192                 :         const mbfl_encoding *encoding;
     193                 :         int i, j;
     194                 : 
     195          153262 :         if (name == NULL) {
     196               8 :                 return NULL;
     197                 :         }
     198                 : 
     199          153254 :         i = 0;
     200         4293854 :         while ((encoding = mbfl_encoding_ptr_list[i++]) != NULL){
     201         4139670 :                 if (strcasecmp(encoding->name, name) == 0) {
     202          152324 :                         return encoding;
     203                 :                 }
     204                 :         }
     205                 : 
     206                 :         /* serch MIME charset name */
     207             930 :         i = 0;
     208           50382 :         while ((encoding = mbfl_encoding_ptr_list[i++]) != NULL) {
     209           48847 :                 if (encoding->mime_name != NULL) {
     210           41407 :                         if (strcasecmp(encoding->mime_name, name) == 0) {
     211             325 :                                 return encoding;
     212                 :                         }
     213                 :                 }
     214                 :         }
     215                 : 
     216                 :         /* serch aliases */
     217             605 :         i = 0;
     218           31181 :         while ((encoding = mbfl_encoding_ptr_list[i++]) != NULL) {
     219           30249 :                 if (encoding->aliases != NULL) {
     220           18658 :                         j = 0;
     221           78113 :                         while ((*encoding->aliases)[j] != NULL) {
     222           41075 :                                 if (strcasecmp((*encoding->aliases)[j], name) == 0) {
     223             278 :                                         return encoding;
     224                 :                                 }
     225           40797 :                                 j++;
     226                 :                         }
     227                 :                 }
     228                 :         }
     229                 : 
     230             327 :         return NULL;
     231                 : }
     232                 : 
     233                 : const mbfl_encoding *
     234                 : mbfl_no2encoding(enum mbfl_no_encoding no_encoding)
     235           44813 : {
     236                 :         const mbfl_encoding *encoding;
     237                 :         int i;
     238                 : 
     239           44813 :         i = 0;
     240          701038 :         while ((encoding = mbfl_encoding_ptr_list[i++]) != NULL){
     241          656225 :                 if (encoding->no_encoding == no_encoding) {
     242           44813 :                         return encoding;
     243                 :                 }
     244                 :         }
     245                 : 
     246               0 :         return NULL;
     247                 : }
     248                 : 
     249                 : enum mbfl_no_encoding
     250                 : mbfl_name2no_encoding(const char *name)
     251          153119 : {
     252                 :         const mbfl_encoding *encoding;
     253                 : 
     254          153119 :         encoding = mbfl_name2encoding(name);
     255          153119 :         if (encoding == NULL) {
     256             335 :                 return mbfl_no_encoding_invalid;
     257                 :         } else {
     258          152784 :                 return encoding->no_encoding;
     259                 :         }
     260                 : }
     261                 : 
     262                 : const char *
     263                 : mbfl_no_encoding2name(enum mbfl_no_encoding no_encoding)
     264             190 : {
     265                 :         const mbfl_encoding *encoding;
     266                 : 
     267             190 :         encoding = mbfl_no2encoding(no_encoding);
     268             190 :         if (encoding == NULL) {
     269               0 :                 return "";
     270                 :         } else {
     271             190 :                 return encoding->name;
     272                 :         }
     273                 : }
     274                 : 
     275                 : const mbfl_encoding **
     276                 : mbfl_get_supported_encodings(void)
     277               0 : {
     278               0 :         return mbfl_encoding_ptr_list;
     279                 : }
     280                 : 
     281                 : const char *
     282                 : mbfl_no2preferred_mime_name(enum mbfl_no_encoding no_encoding)
     283             913 : {
     284                 :         const mbfl_encoding *encoding;
     285                 : 
     286             913 :         encoding = mbfl_no2encoding(no_encoding);
     287             913 :         if (encoding != NULL && encoding->mime_name != NULL && encoding->mime_name[0] != '\0') {
     288             913 :                 return encoding->mime_name;
     289                 :         } else {
     290               0 :                 return NULL;
     291                 :         }
     292                 : }
     293                 : 
     294                 : int
     295                 : mbfl_is_support_encoding(const char *name)
     296               0 : {
     297                 :         const mbfl_encoding *encoding;
     298                 : 
     299               0 :         encoding = mbfl_name2encoding(name);
     300               0 :         if (encoding == NULL) {
     301               0 :                 return 0;
     302                 :         } else {
     303               0 :                 return 1;
     304                 :         }
     305                 : }

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:11 +0000 (5 days ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.