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 - ext/dom - characterdata.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 116 134 86.6 %
Date: 2019-05-06 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) The PHP Group                                          |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Christian Stocker <chregu@php.net>                          |
      16             :    |          Rob Richards <rrichards@php.net>                            |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : #ifdef HAVE_CONFIG_H
      21             : #include "config.h"
      22             : #endif
      23             : 
      24             : #include "php.h"
      25             : #if HAVE_LIBXML && HAVE_DOM
      26             : #include "php_dom.h"
      27             : 
      28             : 
      29             : /* {{{ arginfo */
      30             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_substring_data, 0, 0, 2)
      31             :         ZEND_ARG_INFO(0, offset)
      32             :         ZEND_ARG_INFO(0, count)
      33             : ZEND_END_ARG_INFO();
      34             : 
      35             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_append_data, 0, 0, 1)
      36             :         ZEND_ARG_INFO(0, arg)
      37             : ZEND_END_ARG_INFO();
      38             : 
      39             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_insert_data, 0, 0, 2)
      40             :         ZEND_ARG_INFO(0, offset)
      41             :         ZEND_ARG_INFO(0, arg)
      42             : ZEND_END_ARG_INFO();
      43             : 
      44             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_delete_data, 0, 0, 2)
      45             :         ZEND_ARG_INFO(0, offset)
      46             :         ZEND_ARG_INFO(0, count)
      47             : ZEND_END_ARG_INFO();
      48             : 
      49             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_replace_data, 0, 0, 3)
      50             :         ZEND_ARG_INFO(0, offset)
      51             :         ZEND_ARG_INFO(0, count)
      52             :         ZEND_ARG_INFO(0, arg)
      53             : ZEND_END_ARG_INFO();
      54             : /* }}} */
      55             : 
      56             : /*
      57             : * class DOMCharacterData extends DOMNode
      58             : *
      59             : * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-FF21A306
      60             : * Since:
      61             : */
      62             : 
      63             : const zend_function_entry php_dom_characterdata_class_functions[] = {
      64             :         PHP_FALIAS(substringData, dom_characterdata_substring_data, arginfo_dom_characterdata_substring_data)
      65             :         PHP_FALIAS(appendData, dom_characterdata_append_data, arginfo_dom_characterdata_append_data)
      66             :         PHP_FALIAS(insertData, dom_characterdata_insert_data, arginfo_dom_characterdata_insert_data)
      67             :         PHP_FALIAS(deleteData, dom_characterdata_delete_data, arginfo_dom_characterdata_delete_data)
      68             :         PHP_FALIAS(replaceData, dom_characterdata_replace_data, arginfo_dom_characterdata_replace_data)
      69             :         PHP_FE_END
      70             : };
      71             : 
      72             : /* {{{ data     string
      73             : readonly=no
      74             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-72AB8359
      75             : Since:
      76             : */
      77          12 : int dom_characterdata_data_read(dom_object *obj, zval *retval)
      78             : {
      79          12 :         xmlNodePtr nodep = dom_object_get_node(obj);
      80             :         xmlChar *content;
      81             : 
      82          12 :         if (nodep == NULL) {
      83           1 :                 php_dom_throw_error(INVALID_STATE_ERR, 0);
      84           1 :                 return FAILURE;
      85             :         }
      86             : 
      87          11 :         if ((content = xmlNodeGetContent(nodep)) != NULL) {
      88          22 :                 ZVAL_STRING(retval, (char *) content);
      89          11 :                 xmlFree(content);
      90             :         } else {
      91           0 :                 ZVAL_EMPTY_STRING(retval);
      92             :         }
      93             : 
      94          11 :         return SUCCESS;
      95             : }
      96             : 
      97           3 : int dom_characterdata_data_write(dom_object *obj, zval *newval)
      98             : {
      99           3 :         xmlNode *nodep = dom_object_get_node(obj);
     100             :         zend_string *str;
     101             : 
     102           3 :         if (nodep == NULL) {
     103           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 0);
     104           0 :                 return FAILURE;
     105             :         }
     106             : 
     107           3 :         str = zval_get_string(newval);
     108             : 
     109           3 :         xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
     110             : 
     111             :         zend_string_release_ex(str, 0);
     112           3 :         return SUCCESS;
     113             : }
     114             : 
     115             : /* }}} */
     116             : 
     117             : /* {{{ length   long
     118             : readonly=yes
     119             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-7D61178C
     120             : Since:
     121             : */
     122          11 : int dom_characterdata_length_read(dom_object *obj, zval *retval)
     123             : {
     124          11 :         xmlNodePtr nodep = dom_object_get_node(obj);
     125             :         xmlChar *content;
     126          11 :         long length = 0;
     127             : 
     128          11 :         if (nodep == NULL) {
     129           1 :                 php_dom_throw_error(INVALID_STATE_ERR, 0);
     130           1 :                 return FAILURE;
     131             :         }
     132             : 
     133          10 :         content = xmlNodeGetContent(nodep);
     134             : 
     135          10 :         if (content) {
     136          10 :                 length = xmlUTF8Strlen(content);
     137          10 :                 xmlFree(content);
     138             :         }
     139             : 
     140          10 :         ZVAL_LONG(retval, length);
     141             : 
     142          10 :         return SUCCESS;
     143             : }
     144             : 
     145             : /* }}} */
     146             : 
     147             : /* {{{ proto string dom_characterdata_substring_data(int offset, int count);
     148             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6531BCCF
     149             : Since:
     150             : */
     151           3 : PHP_FUNCTION(dom_characterdata_substring_data)
     152             : {
     153             :         zval       *id;
     154             :         xmlChar    *cur;
     155             :         xmlChar    *substring;
     156             :         xmlNodePtr  node;
     157             :         zend_long        offset, count;
     158             :         int         length;
     159             :         dom_object      *intern;
     160             : 
     161           3 :         id = ZEND_THIS;
     162           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &offset, &count) == FAILURE) {
     163           0 :                 return;
     164             :         }
     165             : 
     166           3 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     167             : 
     168           3 :         cur = xmlNodeGetContent(node);
     169           3 :         if (cur == NULL) {
     170           0 :                 RETURN_FALSE;
     171             :         }
     172             : 
     173           3 :         length = xmlUTF8Strlen(cur);
     174             : 
     175           3 :         if (offset < 0 || count < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count) || offset > length) {
     176           0 :                 xmlFree(cur);
     177           0 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
     178           0 :                 RETURN_FALSE;
     179             :         }
     180             : 
     181           3 :         if ((offset + count) > length) {
     182           0 :                 count = length - offset;
     183             :         }
     184             : 
     185           3 :         substring = xmlUTF8Strsub(cur, (int)offset, (int)count);
     186           3 :         xmlFree(cur);
     187             : 
     188           3 :         if (substring) {
     189           6 :                 RETVAL_STRING((char *) substring);
     190           3 :                 xmlFree(substring);
     191             :         } else {
     192           0 :                 RETVAL_EMPTY_STRING();
     193             :         }
     194             : }
     195             : /* }}} end dom_characterdata_substring_data */
     196             : 
     197             : /* {{{ proto void dom_characterdata_append_data(string arg);
     198             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-32791A2F
     199             : Since:
     200             : */
     201           7 : PHP_FUNCTION(dom_characterdata_append_data)
     202             : {
     203             :         zval *id;
     204             :         xmlNode *nodep;
     205             :         dom_object *intern;
     206             :         char *arg;
     207             :         size_t arg_len;
     208             : 
     209           7 :         id = ZEND_THIS;
     210           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
     211           0 :                 return;
     212             :         }
     213             : 
     214           7 :         DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
     215           7 :         xmlTextConcat(nodep, (xmlChar *) arg, arg_len);
     216           7 :         RETURN_TRUE;
     217             : }
     218             : /* }}} end dom_characterdata_append_data */
     219             : 
     220             : /* {{{ proto void dom_characterdata_insert_data(int offset, string arg);
     221             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-3EDB695F
     222             : Since:
     223             : */
     224           6 : PHP_FUNCTION(dom_characterdata_insert_data)
     225             : {
     226             :         zval *id;
     227             :         xmlChar         *cur, *first, *second;
     228             :         xmlNodePtr  node;
     229             :         char            *arg;
     230             :         zend_long        offset;
     231             :         int         length;
     232             :         size_t arg_len;
     233             :         dom_object      *intern;
     234             : 
     235           6 :         id = ZEND_THIS;
     236           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &offset, &arg, &arg_len) == FAILURE) {
     237           0 :                 return;
     238             :         }
     239             : 
     240           6 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     241             : 
     242           6 :         cur = xmlNodeGetContent(node);
     243           6 :         if (cur == NULL) {
     244           0 :                 RETURN_FALSE;
     245             :         }
     246             : 
     247           6 :         length = xmlUTF8Strlen(cur);
     248             : 
     249           6 :         if (offset < 0 || ZEND_LONG_INT_OVFL(offset) || offset > length) {
     250           2 :                 xmlFree(cur);
     251           2 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
     252           2 :                 RETURN_FALSE;
     253             :         }
     254             : 
     255           4 :         first = xmlUTF8Strndup(cur, (int)offset);
     256           4 :         second = xmlUTF8Strsub(cur, (int)offset, length - (int)offset);
     257           4 :         xmlFree(cur);
     258             : 
     259           4 :         xmlNodeSetContent(node, first);
     260           4 :         xmlNodeAddContent(node, (xmlChar *) arg);
     261           4 :         xmlNodeAddContent(node, second);
     262             : 
     263           4 :         xmlFree(first);
     264           4 :         xmlFree(second);
     265             : 
     266           4 :         RETURN_TRUE;
     267             : }
     268             : /* }}} end dom_characterdata_insert_data */
     269             : 
     270             : /* {{{ proto void dom_characterdata_delete_data(int offset, int count);
     271             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-7C603781
     272             : Since:
     273             : */
     274           4 : PHP_FUNCTION(dom_characterdata_delete_data)
     275             : {
     276             :         zval *id;
     277             :         xmlChar    *cur, *substring, *second;
     278             :         xmlNodePtr  node;
     279             :         zend_long        offset, count;
     280             :         int         length;
     281             :         dom_object      *intern;
     282             : 
     283           4 :         id = ZEND_THIS;
     284           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &offset, &count) == FAILURE) {
     285           0 :                 return;
     286             :         }
     287             : 
     288           4 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     289             : 
     290           4 :         cur = xmlNodeGetContent(node);
     291           4 :         if (cur == NULL) {
     292           0 :                 RETURN_FALSE;
     293             :         }
     294             : 
     295           4 :         length = xmlUTF8Strlen(cur);
     296             : 
     297           4 :         if (offset < 0 || count < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count) || offset > length) {
     298           1 :                 xmlFree(cur);
     299           1 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
     300           1 :                 RETURN_FALSE;
     301             :         }
     302             : 
     303           3 :         if (offset > 0) {
     304           3 :                 substring = xmlUTF8Strsub(cur, 0, (int)offset);
     305             :         } else {
     306           0 :                 substring = NULL;
     307             :         }
     308             : 
     309           3 :         if ((offset + count) > length) {
     310           1 :                 count = length - offset;
     311             :         }
     312             : 
     313           3 :         second = xmlUTF8Strsub(cur, (int)offset + (int)count, length - (int)offset);
     314           3 :         substring = xmlStrcat(substring, second);
     315             : 
     316           3 :         xmlNodeSetContent(node, substring);
     317             : 
     318           3 :         xmlFree(cur);
     319           3 :         xmlFree(second);
     320           3 :         xmlFree(substring);
     321             : 
     322           3 :         RETURN_TRUE;
     323             : }
     324             : /* }}} end dom_characterdata_delete_data */
     325             : 
     326             : /* {{{ proto void dom_characterdata_replace_data(int offset, int count, string arg);
     327             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-E5CBA7FB
     328             : Since:
     329             : */
     330           6 : PHP_FUNCTION(dom_characterdata_replace_data)
     331             : {
     332             :         zval *id;
     333           6 :         xmlChar         *cur, *substring, *second = NULL;
     334             :         xmlNodePtr  node;
     335             :         char            *arg;
     336             :         zend_long        offset, count;
     337             :         int         length;
     338             :         size_t arg_len;
     339             :         dom_object      *intern;
     340             : 
     341           6 :         id = ZEND_THIS;
     342           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "lls", &offset, &count, &arg, &arg_len) == FAILURE) {
     343           0 :                 return;
     344             :         }
     345             : 
     346           6 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     347             : 
     348           6 :         cur = xmlNodeGetContent(node);
     349           6 :         if (cur == NULL) {
     350           0 :                 RETURN_FALSE;
     351             :         }
     352             : 
     353           6 :         length = xmlUTF8Strlen(cur);
     354             : 
     355           6 :         if (offset < 0 || count < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count) || offset > length) {
     356           2 :                 xmlFree(cur);
     357           2 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
     358           2 :                 RETURN_FALSE;
     359             :         }
     360             : 
     361           4 :         if (offset > 0) {
     362           3 :                 substring = xmlUTF8Strsub(cur, 0, (int)offset);
     363             :         } else {
     364           1 :                 substring = NULL;
     365             :         }
     366             : 
     367           4 :         if ((offset + count) > length) {
     368           1 :                 count = length - offset;
     369             :         }
     370             : 
     371           4 :         if (offset < length) {
     372           4 :                 second = xmlUTF8Strsub(cur, (int)offset + count, length - (int)offset);
     373             :         }
     374             : 
     375           4 :         substring = xmlStrcat(substring, (xmlChar *) arg);
     376           4 :         substring = xmlStrcat(substring, second);
     377             : 
     378           4 :         xmlNodeSetContent(node, substring);
     379             : 
     380           4 :         xmlFree(cur);
     381           4 :         if (second) {
     382           4 :                 xmlFree(second);
     383             :         }
     384           4 :         xmlFree(substring);
     385             : 
     386           4 :         RETURN_TRUE;
     387             : }
     388             : /* }}} end dom_characterdata_replace_data */
     389             : 
     390             : #endif

Generated by: LCOV version 1.10

Generated at Mon, 06 May 2019 17:58:13 +0000 (998 days ago)

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