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: 115 129 89.1 %
Date: 2014-09-19 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 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             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : #if HAVE_LIBXML && HAVE_DOM
      28             : #include "php_dom.h"
      29             : 
      30             : 
      31             : /* {{{ arginfo */
      32             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_substring_data, 0, 0, 2)
      33             :         ZEND_ARG_INFO(0, offset)
      34             :         ZEND_ARG_INFO(0, count)
      35             : ZEND_END_ARG_INFO();
      36             : 
      37             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_append_data, 0, 0, 1)
      38             :         ZEND_ARG_INFO(0, arg)
      39             : ZEND_END_ARG_INFO();
      40             : 
      41             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_insert_data, 0, 0, 2)
      42             :         ZEND_ARG_INFO(0, offset)
      43             :         ZEND_ARG_INFO(0, arg)
      44             : ZEND_END_ARG_INFO();
      45             : 
      46             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_delete_data, 0, 0, 2)
      47             :         ZEND_ARG_INFO(0, offset)
      48             :         ZEND_ARG_INFO(0, count)
      49             : ZEND_END_ARG_INFO();
      50             : 
      51             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_characterdata_replace_data, 0, 0, 3)
      52             :         ZEND_ARG_INFO(0, offset)
      53             :         ZEND_ARG_INFO(0, count)
      54             :         ZEND_ARG_INFO(0, arg)
      55             : ZEND_END_ARG_INFO();
      56             : /* }}} */
      57             : 
      58             : /*
      59             : * class DOMCharacterData extends DOMNode 
      60             : *
      61             : * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-FF21A306
      62             : * Since: 
      63             : */
      64             : 
      65             : const zend_function_entry php_dom_characterdata_class_functions[] = {
      66             :         PHP_FALIAS(substringData, dom_characterdata_substring_data, arginfo_dom_characterdata_substring_data)
      67             :         PHP_FALIAS(appendData, dom_characterdata_append_data, arginfo_dom_characterdata_append_data)
      68             :         PHP_FALIAS(insertData, dom_characterdata_insert_data, arginfo_dom_characterdata_insert_data)
      69             :         PHP_FALIAS(deleteData, dom_characterdata_delete_data, arginfo_dom_characterdata_delete_data)
      70             :         PHP_FALIAS(replaceData, dom_characterdata_replace_data, arginfo_dom_characterdata_replace_data)
      71             :         PHP_FE_END
      72             : };
      73             : 
      74             : /* {{{ data     string  
      75             : readonly=no 
      76             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-72AB8359
      77             : Since: 
      78             : */
      79          10 : int dom_characterdata_data_read(dom_object *obj, zval *retval TSRMLS_DC)
      80             : {
      81          10 :         xmlNodePtr nodep = dom_object_get_node(obj);
      82             :         xmlChar *content;
      83             : 
      84          10 :         if (nodep == NULL) {
      85           1 :                 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
      86           1 :                 return FAILURE;
      87             :         }
      88             : 
      89           9 :         if ((content = xmlNodeGetContent(nodep)) != NULL) {
      90          18 :                 ZVAL_STRING(retval, (char *) content);
      91           9 :                 xmlFree(content);
      92             :         } else {
      93           0 :                 ZVAL_EMPTY_STRING(retval);
      94             :         }
      95             : 
      96           9 :         return SUCCESS;
      97             : }
      98             : 
      99           3 : int dom_characterdata_data_write(dom_object *obj, zval *newval TSRMLS_DC)
     100             : {
     101           3 :         xmlNode *nodep = dom_object_get_node(obj);
     102             :         zend_string *str;
     103             : 
     104           3 :         if (nodep == NULL) {
     105           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
     106           0 :                 return FAILURE;
     107             :         }
     108             : 
     109           3 :         str = zval_get_string(newval);
     110             : 
     111           3 :         xmlNodeSetContentLen(nodep, (xmlChar *) str->val, str->len + 1);
     112             : 
     113             :         zend_string_release(str);
     114           3 :         return SUCCESS;
     115             : }
     116             : 
     117             : /* }}} */
     118             : 
     119             : /* {{{ length   long    
     120             : readonly=yes 
     121             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-7D61178C
     122             : Since: 
     123             : */
     124           9 : int dom_characterdata_length_read(dom_object *obj, zval *retval TSRMLS_DC)
     125             : {
     126           9 :         xmlNodePtr nodep = dom_object_get_node(obj);
     127             :         xmlChar *content;
     128           9 :         long length = 0;
     129             : 
     130           9 :         if (nodep == NULL) {
     131           1 :                 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
     132           1 :                 return FAILURE;
     133             :         }
     134             : 
     135           8 :         content = xmlNodeGetContent(nodep);
     136             : 
     137           8 :         if (content) {
     138           8 :                 length = xmlUTF8Strlen(content);
     139           8 :                 xmlFree(content);
     140             :         }
     141             : 
     142           8 :         ZVAL_LONG(retval, length);
     143             : 
     144           8 :         return SUCCESS;
     145             : }
     146             : 
     147             : /* }}} */
     148             : 
     149             : /* {{{ proto string dom_characterdata_substring_data(int offset, int count);
     150             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6531BCCF
     151             : Since: 
     152             : */
     153           3 : PHP_FUNCTION(dom_characterdata_substring_data)
     154             : {
     155             :         zval       *id;
     156             :         xmlChar    *cur;
     157             :         xmlChar    *substring;
     158             :         xmlNodePtr  node;
     159             :         zend_long        offset, count;
     160             :         int         length;
     161             :         dom_object      *intern;
     162             : 
     163           3 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &id, dom_characterdata_class_entry, &offset, &count) == FAILURE) {
     164           0 :                 return;
     165             :         }
     166             : 
     167           3 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     168             : 
     169           3 :         cur = xmlNodeGetContent(node);
     170           3 :         if (cur == NULL) {
     171           0 :                 RETURN_FALSE;
     172             :         }
     173             : 
     174           3 :         length = xmlUTF8Strlen(cur);
     175             : 
     176           3 :         if (offset < 0 || count < 0 || offset > length) {
     177           0 :                 xmlFree(cur);
     178           0 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
     179           0 :                 RETURN_FALSE;
     180             :         }
     181             : 
     182           3 :         if ((offset + count) > length) {
     183           0 :                 count = length - offset;
     184             :         }
     185             : 
     186           3 :         substring = xmlUTF8Strsub(cur, offset, count);
     187           3 :         xmlFree(cur);
     188             : 
     189           3 :         if (substring) {
     190           6 :                 RETVAL_STRING((char *) substring);
     191           3 :                 xmlFree(substring);
     192             :         } else {
     193           0 :                 RETVAL_EMPTY_STRING();
     194             :         }
     195             : }
     196             : /* }}} end dom_characterdata_substring_data */
     197             : 
     198             : /* {{{ proto void dom_characterdata_append_data(string arg);
     199             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-32791A2F
     200             : Since: 
     201             : */
     202           8 : PHP_FUNCTION(dom_characterdata_append_data)
     203             : {
     204             :         zval *id;
     205             :         xmlNode *nodep;
     206             :         dom_object *intern;
     207             :         char *arg;
     208             :         size_t arg_len;
     209             : 
     210           8 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_characterdata_class_entry, &arg, &arg_len) == FAILURE) {
     211           1 :                 return;
     212             :         }
     213             : 
     214           7 :         DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
     215             : #if LIBXML_VERSION < 20627
     216             : /* Implement logic from libxml xmlTextConcat to add suport for comments and PI */
     217             :     if ((nodep->content == (xmlChar *) &(nodep->properties)) ||
     218             :         ((nodep->doc != NULL) && (nodep->doc->dict != NULL) &&
     219             :                 xmlDictOwns(nodep->doc->dict, nodep->content))) {
     220             :         nodep->content = xmlStrncatNew(nodep->content, arg, arg_len);
     221             :     } else {
     222             :         nodep->content = xmlStrncat(nodep->content, arg, arg_len);
     223             :     }
     224             :     nodep->properties = NULL;
     225             : #else
     226           7 :         xmlTextConcat(nodep, (xmlChar *) arg, arg_len);
     227             : #endif
     228           7 :         RETURN_TRUE;
     229             : }
     230             : /* }}} end dom_characterdata_append_data */
     231             : 
     232             : /* {{{ proto void dom_characterdata_insert_data(int offset, string arg);
     233             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-3EDB695F
     234             : Since: 
     235             : */
     236           7 : PHP_FUNCTION(dom_characterdata_insert_data)
     237             : {
     238             :         zval *id;
     239             :         xmlChar         *cur, *first, *second;
     240             :         xmlNodePtr  node;
     241             :         char            *arg;
     242             :         zend_long        offset;
     243             :         int         length;
     244             :         size_t arg_len;
     245             :         dom_object      *intern;
     246             : 
     247           7 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols", &id, dom_characterdata_class_entry, &offset, &arg, &arg_len) == FAILURE) {
     248           1 :                 return;
     249             :         }
     250             : 
     251           6 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     252             : 
     253           6 :         cur = xmlNodeGetContent(node);
     254           6 :         if (cur == NULL) {
     255           0 :                 RETURN_FALSE;
     256             :         }
     257             : 
     258           6 :         length = xmlUTF8Strlen(cur);
     259             : 
     260           6 :         if (offset < 0 || offset > length) {
     261           2 :                 xmlFree(cur);
     262           2 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
     263           2 :                 RETURN_FALSE;
     264             :         }
     265             : 
     266           4 :         first = xmlUTF8Strndup(cur, offset);
     267           4 :         second = xmlUTF8Strsub(cur, offset, length - offset);
     268           4 :         xmlFree(cur);
     269             : 
     270           4 :         xmlNodeSetContent(node, first);
     271           4 :         xmlNodeAddContent(node, (xmlChar *) arg);
     272           4 :         xmlNodeAddContent(node, second);
     273             :         
     274           4 :         xmlFree(first);
     275           4 :         xmlFree(second);
     276             : 
     277           4 :         RETURN_TRUE;
     278             : }
     279             : /* }}} end dom_characterdata_insert_data */
     280             : 
     281             : /* {{{ proto void dom_characterdata_delete_data(int offset, int count);
     282             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-7C603781
     283             : Since: 
     284             : */
     285           5 : PHP_FUNCTION(dom_characterdata_delete_data)
     286             : {
     287             :         zval *id;
     288             :         xmlChar    *cur, *substring, *second;
     289             :         xmlNodePtr  node;
     290             :         zend_long        offset, count;
     291             :         int         length;
     292             :         dom_object      *intern;
     293             : 
     294           5 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &id, dom_characterdata_class_entry, &offset, &count) == FAILURE) {
     295           1 :                 return;
     296             :         }
     297             : 
     298           4 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     299             : 
     300           4 :         cur = xmlNodeGetContent(node);
     301           4 :         if (cur == NULL) {
     302           0 :                 RETURN_FALSE;
     303             :         }
     304             : 
     305           4 :         length = xmlUTF8Strlen(cur);
     306             : 
     307           4 :         if (offset < 0 || count < 0 || offset > length) {
     308           1 :                 xmlFree(cur);
     309           1 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
     310           1 :                 RETURN_FALSE;
     311             :         }
     312             : 
     313           3 :         if (offset > 0) {
     314           3 :                 substring = xmlUTF8Strsub(cur, 0, offset);
     315             :         } else {
     316           0 :                 substring = NULL;
     317             :         }
     318             : 
     319           3 :         if ((offset + count) > length) {
     320           1 :                 count = length - offset;
     321             :         }
     322             : 
     323           3 :         second = xmlUTF8Strsub(cur, offset + count, length - offset);
     324           3 :         substring = xmlStrcat(substring, second);
     325             : 
     326           3 :         xmlNodeSetContent(node, substring);
     327             : 
     328           3 :         xmlFree(cur);
     329           3 :         xmlFree(second);
     330           3 :         xmlFree(substring);
     331             : 
     332           3 :         RETURN_TRUE;
     333             : }
     334             : /* }}} end dom_characterdata_delete_data */
     335             : 
     336             : /* {{{ proto void dom_characterdata_replace_data(int offset, int count, string arg);
     337             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-E5CBA7FB
     338             : Since: 
     339             : */
     340           7 : PHP_FUNCTION(dom_characterdata_replace_data)
     341             : {
     342             :         zval *id;
     343           7 :         xmlChar         *cur, *substring, *second = NULL;
     344             :         xmlNodePtr  node;
     345             :         char            *arg;
     346             :         zend_long        offset, count;
     347             :         int         length;
     348             :         size_t arg_len;
     349             :         dom_object      *intern;
     350             : 
     351           7 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olls", &id, dom_characterdata_class_entry, &offset, &count, &arg, &arg_len) == FAILURE) {
     352           1 :                 return;
     353             :         }
     354             : 
     355           6 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     356             : 
     357           6 :         cur = xmlNodeGetContent(node);
     358           6 :         if (cur == NULL) {
     359           0 :                 RETURN_FALSE;
     360             :         }
     361             : 
     362           6 :         length = xmlUTF8Strlen(cur);
     363             : 
     364           6 :         if (offset < 0 || count < 0 || offset > length) {
     365           2 :                 xmlFree(cur);
     366           2 :                 php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
     367           2 :                 RETURN_FALSE;
     368             :         }
     369             : 
     370           4 :         if (offset > 0) {
     371           3 :                 substring = xmlUTF8Strsub(cur, 0, offset);
     372             :         } else {
     373           1 :                 substring = NULL;
     374             :         }
     375             : 
     376           4 :         if ((offset + count) > length) {
     377           1 :                 count = length - offset;
     378             :         }
     379             : 
     380           4 :         if (offset < length) {
     381           4 :                 second = xmlUTF8Strsub(cur, offset + count, length - offset);
     382             :         }
     383             : 
     384           4 :         substring = xmlStrcat(substring, (xmlChar *) arg);
     385           4 :         substring = xmlStrcat(substring, second);
     386             : 
     387           4 :         xmlNodeSetContent(node, substring);
     388             : 
     389           4 :         xmlFree(cur);
     390           4 :         if (second) {
     391           4 :                 xmlFree(second);
     392             :         }
     393           4 :         xmlFree(substring);
     394             : 
     395           4 :         RETURN_TRUE;
     396             : }
     397             : /* }}} end dom_characterdata_replace_data */
     398             : 
     399             : #endif
     400             : 
     401             : /*
     402             :  * Local variables:
     403             :  * tab-width: 4
     404             :  * c-basic-offset: 4
     405             :  * End:
     406             :  * vim600: noet sw=4 ts=4 fdm=marker
     407             :  * vim<600: noet sw=4 ts=4
     408             :  */

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:06 +0000 (2 days ago)

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