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

LCOV - code coverage report
Current view: top level - Zend - zend_multibyte.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 51 82 62.2 %
Date: 2016-08-24 Functions: 13 22 59.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at                              |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Masaki Fujimoto <fujimoto@php.net>                          |
      16             :    |          Rui Hirokawa <hirokawa@php.net>                             |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "zend.h"
      23             : #include "zend_compile.h"
      24             : #include "zend_operators.h"
      25             : #include "zend_multibyte.h"
      26             : #include "zend_ini.h"
      27             : 
      28           0 : static const zend_encoding *dummy_encoding_fetcher(const char *encoding_name)
      29             : {
      30           0 :         return NULL;
      31             : }
      32             : 
      33           0 : static const char *dummy_encoding_name_getter(const zend_encoding *encoding)
      34             : {
      35           0 :         return (const char*)encoding;
      36             : }
      37             : 
      38           0 : static int dummy_encoding_lexer_compatibility_checker(const zend_encoding *encoding)
      39             : {
      40           0 :         return 0;
      41             : }
      42             : 
      43           0 : static const zend_encoding *dummy_encoding_detector(const unsigned char *string, size_t length, const zend_encoding **list, size_t list_size)
      44             : {
      45           0 :         return NULL;
      46             : }
      47             : 
      48           0 : static size_t dummy_encoding_converter(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length, const zend_encoding *encoding_to, const zend_encoding *encoding_from)
      49             : {
      50           0 :         return (size_t)-1;
      51             : }
      52             : 
      53           0 : static int dummy_encoding_list_parser(const char *encoding_list, size_t encoding_list_len, const zend_encoding ***return_list, size_t *return_size, int persistent)
      54             : {
      55           0 :         *return_list = pemalloc(0, persistent);
      56           0 :         *return_size = 0;
      57           0 :         return SUCCESS;
      58             : }
      59             : 
      60           0 : static const zend_encoding *dummy_internal_encoding_getter(void)
      61             : {
      62           0 :         return NULL;
      63             : }
      64             : 
      65           0 : static int dummy_internal_encoding_setter(const zend_encoding *encoding)
      66             : {
      67           0 :         return FAILURE;
      68             : }
      69             : 
      70             : static zend_multibyte_functions multibyte_functions_dummy;
      71             : static zend_multibyte_functions multibyte_functions = {
      72             :         NULL,
      73             :         dummy_encoding_fetcher,
      74             :         dummy_encoding_name_getter,
      75             :         dummy_encoding_lexer_compatibility_checker,
      76             :         dummy_encoding_detector,
      77             :         dummy_encoding_converter,
      78             :         dummy_encoding_list_parser,
      79             :         dummy_internal_encoding_getter,
      80             :         dummy_internal_encoding_setter
      81             : };
      82             : 
      83             : ZEND_API const zend_encoding *zend_multibyte_encoding_utf32be = (const zend_encoding*)"UTF-32BE";
      84             : ZEND_API const zend_encoding *zend_multibyte_encoding_utf32le = (const zend_encoding*)"UTF-32LE";
      85             : ZEND_API const zend_encoding *zend_multibyte_encoding_utf16be = (const zend_encoding*)"UTF-16BE";
      86             : ZEND_API const zend_encoding *zend_multibyte_encoding_utf16le = (const zend_encoding*)"UTF-32LE";
      87             : ZEND_API const zend_encoding *zend_multibyte_encoding_utf8 = (const zend_encoding*)"UTF-8";
      88             : 
      89       23504 : ZEND_API int zend_multibyte_set_functions(const zend_multibyte_functions *functions)
      90             : {
      91       23504 :         zend_multibyte_encoding_utf32be = functions->encoding_fetcher("UTF-32BE");
      92       23504 :         if (!zend_multibyte_encoding_utf32be) {
      93           0 :                 return FAILURE;
      94             :         }
      95       23504 :         zend_multibyte_encoding_utf32le = functions->encoding_fetcher("UTF-32LE");
      96       23504 :         if (!zend_multibyte_encoding_utf32le) {
      97           0 :                 return FAILURE;
      98             :         }
      99       23504 :         zend_multibyte_encoding_utf16be = functions->encoding_fetcher("UTF-16BE");
     100       23504 :         if (!zend_multibyte_encoding_utf16be) {
     101           0 :                 return FAILURE;
     102             :         }
     103       23504 :         zend_multibyte_encoding_utf16le = functions->encoding_fetcher("UTF-16LE");
     104       23504 :         if (!zend_multibyte_encoding_utf16le) {
     105           0 :                 return FAILURE;
     106             :         }
     107       23504 :         zend_multibyte_encoding_utf8 = functions->encoding_fetcher("UTF-8");
     108       23504 :         if (!zend_multibyte_encoding_utf8) {
     109           0 :                 return FAILURE;
     110             :         }
     111             : 
     112       23504 :         multibyte_functions_dummy = multibyte_functions;
     113       23504 :         multibyte_functions = *functions;
     114             : 
     115             :         /* As zend_multibyte_set_functions() gets called after ini settings were
     116             :          * populated, we need to reinitialize script_encoding here.
     117             :          */
     118             :         {
     119       23504 :                 const char *value = zend_ini_string("zend.script_encoding", sizeof("zend.script_encoding") - 1, 0);
     120       23504 :                 zend_multibyte_set_script_encoding_by_string(value, strlen(value));
     121             :         }
     122       23504 :         return SUCCESS;
     123             : }
     124             : 
     125       23544 : ZEND_API void zend_multibyte_restore_functions(void)
     126             : {
     127       23544 :         multibyte_functions = multibyte_functions_dummy;
     128       23544 : }
     129             : 
     130         184 : ZEND_API const zend_multibyte_functions *zend_multibyte_get_functions(void)
     131             : {
     132         184 :         return multibyte_functions.provider_name ? &multibyte_functions: NULL;
     133             : }
     134             : 
     135          44 : ZEND_API const zend_encoding *zend_multibyte_fetch_encoding(const char *name)
     136             : {
     137          44 :         return multibyte_functions.encoding_fetcher(name);
     138             : }
     139             : 
     140          18 : ZEND_API const char *zend_multibyte_get_encoding_name(const zend_encoding *encoding)
     141             : {
     142          18 :         return multibyte_functions.encoding_name_getter(encoding);
     143             : }
     144             : 
     145          46 : ZEND_API int zend_multibyte_check_lexer_compatibility(const zend_encoding *encoding)
     146             : {
     147          46 :         return multibyte_functions.lexer_compatibility_checker(encoding);
     148             : }
     149             : 
     150           3 : ZEND_API const zend_encoding *zend_multibyte_encoding_detector(const unsigned char *string, size_t length, const zend_encoding **list, size_t list_size)
     151             : {
     152           3 :         return multibyte_functions.encoding_detector(string, length, list, list_size);
     153             : }
     154             : 
     155          87 : ZEND_API size_t zend_multibyte_encoding_converter(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length, const zend_encoding *encoding_to, const zend_encoding *encoding_from)
     156             : {
     157          87 :         return multibyte_functions.encoding_converter(to, to_length, from, from_length, encoding_to, encoding_from);
     158             : }
     159             : 
     160      141024 : ZEND_API int zend_multibyte_parse_encoding_list(const char *encoding_list, size_t encoding_list_len, const zend_encoding ***return_list, size_t *return_size, int persistent)
     161             : {
     162      141024 :         return multibyte_functions.encoding_list_parser(encoding_list, encoding_list_len, return_list, return_size, persistent);
     163             : }
     164             : 
     165         169 : ZEND_API const zend_encoding *zend_multibyte_get_internal_encoding(void)
     166             : {
     167         169 :         return multibyte_functions.internal_encoding_getter();
     168             : }
     169             : 
     170           0 : ZEND_API const zend_encoding *zend_multibyte_get_script_encoding(void)
     171             : {
     172           0 :         return LANG_SCNG(script_encoding);
     173             : }
     174             : 
     175          18 : ZEND_API int zend_multibyte_set_script_encoding(const zend_encoding **encoding_list, size_t encoding_list_size)
     176             : {
     177          18 :         if (CG(script_encoding_list)) {
     178           0 :                 free((char*)CG(script_encoding_list));
     179             :         }
     180          18 :         CG(script_encoding_list) = encoding_list;
     181          18 :         CG(script_encoding_list_size) = encoding_list_size;
     182          18 :         return SUCCESS;
     183             : }
     184             : 
     185       23458 : ZEND_API int zend_multibyte_set_internal_encoding(const zend_encoding *encoding)
     186             : {
     187       23458 :         return multibyte_functions.internal_encoding_setter(encoding);
     188             : }
     189             : 
     190       23504 : ZEND_API int zend_multibyte_set_script_encoding_by_string(const char *new_value, size_t new_value_length)
     191             : {
     192       23504 :         const zend_encoding **list = 0;
     193       23504 :         size_t size = 0;
     194             : 
     195       23504 :         if (!new_value) {
     196           0 :                 zend_multibyte_set_script_encoding(NULL, 0);
     197           0 :                 return SUCCESS;
     198             :         }
     199             : 
     200       23504 :         if (FAILURE == zend_multibyte_parse_encoding_list(new_value, new_value_length, &list, &size, 1)) {
     201       23486 :                 return FAILURE;
     202             :         }
     203             : 
     204          18 :         if (size == 0) {
     205           0 :                 pefree((void*)list, 1);
     206           0 :                 return FAILURE;
     207             :         }
     208             : 
     209          18 :         if (FAILURE == zend_multibyte_set_script_encoding(list, size)) {
     210           0 :                 return FAILURE;
     211             :         }
     212             : 
     213          18 :         return SUCCESS;
     214             : }
     215             : 
     216             : /*
     217             :  * Local variables:
     218             :  * tab-width: 4
     219             :  * c-basic-offset: 4
     220             :  * End:
     221             :  * vim600: sw=4 ts=4 tw=78
     222             :  * vim<600: sw=4 ts=4 tw=78
     223             :  */

Generated by: LCOV version 1.10

Generated at Wed, 24 Aug 2016 12:20:17 +0000 (3 days ago)

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