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 - text.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 52 69 75.4 %
Date: 2019-05-06 Functions: 4 5 80.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             : #include "dom_ce.h"
      28             : 
      29             : /* {{{ arginfo */
      30             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_split_text, 0, 0, 1)
      31             :         ZEND_ARG_INFO(0, offset)
      32             : ZEND_END_ARG_INFO();
      33             : 
      34             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_is_whitespace_in_element_content, 0, 0, 0)
      35             : ZEND_END_ARG_INFO();
      36             : 
      37             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_replace_whole_text, 0, 0, 1)
      38             :         ZEND_ARG_INFO(0, content)
      39             : ZEND_END_ARG_INFO();
      40             : 
      41             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_text_construct, 0, 0, 0)
      42             :         ZEND_ARG_INFO(0, value)
      43             : ZEND_END_ARG_INFO();
      44             : /* }}} */
      45             : 
      46             : /*
      47             : * class DOMText extends DOMCharacterData
      48             : *
      49             : * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1312295772
      50             : * Since:
      51             : */
      52             : 
      53             : const zend_function_entry php_dom_text_class_functions[] = {
      54             :         PHP_FALIAS(splitText, dom_text_split_text, arginfo_dom_text_split_text)
      55             :         PHP_FALIAS(isWhitespaceInElementContent, dom_text_is_whitespace_in_element_content, arginfo_dom_text_is_whitespace_in_element_content)
      56             :         PHP_FALIAS(isElementContentWhitespace, dom_text_is_whitespace_in_element_content, arginfo_dom_text_is_whitespace_in_element_content)
      57             :         PHP_FALIAS(replaceWholeText, dom_text_replace_whole_text, arginfo_dom_text_replace_whole_text)
      58             :         PHP_ME(domtext, __construct, arginfo_dom_text_construct, ZEND_ACC_PUBLIC)
      59             :         PHP_FE_END
      60             : };
      61             : 
      62             : /* {{{ proto DOMText::__construct([string value]); */
      63           2 : PHP_METHOD(domtext, __construct)
      64             : {
      65           2 :         xmlNodePtr nodep = NULL, oldnode = NULL;
      66             :         dom_object *intern;
      67           2 :         char *value = NULL;
      68             :         size_t value_len;
      69             : 
      70           2 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|s", &value, &value_len) == FAILURE) {
      71           0 :                 return;
      72             :         }
      73             : 
      74           2 :         nodep = xmlNewText((xmlChar *) value);
      75             : 
      76           2 :         if (!nodep) {
      77           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 1);
      78           0 :                 RETURN_FALSE;
      79             :         }
      80             : 
      81           2 :         intern = Z_DOMOBJ_P(ZEND_THIS);
      82           2 :         if (intern != NULL) {
      83           2 :                 oldnode = dom_object_get_node(intern);
      84           2 :                 if (oldnode != NULL) {
      85           0 :                         php_libxml_node_free_resource(oldnode );
      86             :                 }
      87           2 :                 php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
      88             :         }
      89             : }
      90             : /* }}} end DOMText::__construct */
      91             : 
      92             : /* {{{ wholeText        string
      93             : readonly=yes
      94             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Text3-wholeText
      95             : Since: DOM Level 3
      96             : */
      97          10 : int dom_text_whole_text_read(dom_object *obj, zval *retval)
      98             : {
      99             :         xmlNodePtr node;
     100          10 :         xmlChar *wholetext = NULL;
     101             : 
     102          10 :         node = dom_object_get_node(obj);
     103             : 
     104          10 :         if (node == NULL) {
     105           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 0);
     106           0 :                 return FAILURE;
     107             :         }
     108             : 
     109             :         /* Find starting text node */
     110          21 :         while (node->prev && ((node->prev->type == XML_TEXT_NODE) || (node->prev->type == XML_CDATA_SECTION_NODE))) {
     111           1 :                 node = node->prev;
     112             :         }
     113             : 
     114             :         /* concatenate all adjacent text and cdata nodes */
     115          34 :         while (node && ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE))) {
     116          14 :                 wholetext = xmlStrcat(wholetext, node->content);
     117          14 :                 node = node->next;
     118             :         }
     119             : 
     120          10 :         if (wholetext != NULL) {
     121          20 :                 ZVAL_STRING(retval, (char *) wholetext);
     122          10 :                 xmlFree(wholetext);
     123             :         } else {
     124           0 :                 ZVAL_EMPTY_STRING(retval);
     125             :         }
     126             : 
     127          10 :         return SUCCESS;
     128             : }
     129             : 
     130             : /* }}} */
     131             : 
     132             : /* {{{ proto DOMText dom_text_split_text(int offset)
     133             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-38853C1D
     134             : Since:
     135             : */
     136           7 : PHP_FUNCTION(dom_text_split_text)
     137             : {
     138             :         zval       *id;
     139             :         xmlChar    *cur;
     140             :         xmlChar    *first;
     141             :         xmlChar    *second;
     142             :         xmlNodePtr  node;
     143             :         xmlNodePtr  nnode;
     144             :         zend_long        offset;
     145             :         int         length;
     146             :         dom_object      *intern;
     147             : 
     148           7 :         id = ZEND_THIS;
     149           7 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &offset) == FAILURE) {
     150           0 :                 return;
     151             :         }
     152           7 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     153             : 
     154           7 :         if (node->type != XML_TEXT_NODE && node->type != XML_CDATA_SECTION_NODE) {
     155           0 :                 RETURN_FALSE;
     156             :         }
     157             : 
     158           7 :         cur = xmlNodeGetContent(node);
     159           7 :         if (cur == NULL) {
     160           0 :                 RETURN_FALSE;
     161             :         }
     162           7 :         length = xmlUTF8Strlen(cur);
     163             : 
     164           7 :         if (ZEND_LONG_INT_OVFL(offset) || (int)offset > length || offset < 0) {
     165           0 :                 xmlFree(cur);
     166           0 :                 RETURN_FALSE;
     167             :         }
     168             : 
     169           7 :         first = xmlUTF8Strndup(cur, (int)offset);
     170           7 :         second = xmlUTF8Strsub(cur, (int)offset, (int)(length - offset));
     171             : 
     172           7 :         xmlFree(cur);
     173             : 
     174           7 :         xmlNodeSetContent(node, first);
     175           7 :         nnode = xmlNewDocText(node->doc, second);
     176             : 
     177           7 :         xmlFree(first);
     178           7 :         xmlFree(second);
     179             : 
     180           7 :         if (nnode == NULL) {
     181           0 :                 RETURN_FALSE;
     182             :         }
     183             : 
     184           7 :         if (node->parent != NULL) {
     185           4 :                 nnode->type = XML_ELEMENT_NODE;
     186           4 :                 xmlAddNextSibling(node, nnode);
     187           4 :                 nnode->type = XML_TEXT_NODE;
     188             :         }
     189             : 
     190           7 :         php_dom_create_object(nnode, return_value, intern);
     191             : }
     192             : /* }}} end dom_text_split_text */
     193             : 
     194             : /* {{{ proto bool dom_text_is_whitespace_in_element_content()
     195             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Text3-isWhitespaceInElementContent
     196             : Since: DOM Level 3
     197             : */
     198           1 : PHP_FUNCTION(dom_text_is_whitespace_in_element_content)
     199             : {
     200             :         zval       *id;
     201             :         xmlNodePtr  node;
     202             :         dom_object      *intern;
     203             : 
     204           1 :         id = ZEND_THIS;
     205           1 :         if (zend_parse_parameters_none() == FAILURE) {
     206           0 :                 return;
     207             :         }
     208           1 :         DOM_GET_OBJ(node, id, xmlNodePtr, intern);
     209             : 
     210           1 :         if (xmlIsBlankNode(node)) {
     211           1 :                 RETURN_TRUE;
     212             :         } else {
     213           0 :                 RETURN_FALSE;
     214             :         }
     215             : }
     216             : /* }}} end dom_text_is_whitespace_in_element_content */
     217             : 
     218             : /* {{{ proto DOMText dom_text_replace_whole_text(string content)
     219             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Text3-replaceWholeText
     220             : Since: DOM Level 3
     221             : */
     222           0 : PHP_FUNCTION(dom_text_replace_whole_text)
     223             : {
     224           0 :  DOM_NOT_IMPLEMENTED();
     225             : }
     226             : /* }}} end dom_text_replace_whole_text */
     227             : 
     228             : #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.