php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
text.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Christian Stocker <chregu@php.net> |
14 | Rob Richards <rrichards@php.net> |
15 +----------------------------------------------------------------------+
16*/
17
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include "php.h"
23#if defined(HAVE_LIBXML) && defined(HAVE_DOM)
24#include "php_dom.h"
25#include "dom_properties.h"
26
27/*
28* class DOMText extends DOMCharacterData
29*
30* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1312295772
31* Since:
32*/
33
34/* {{{ */
35PHP_METHOD(DOMText, __construct)
36{
37 xmlNodePtr nodep = NULL, oldnode = NULL;
38 dom_object *intern;
39 char *value = NULL;
40 size_t value_len;
41
42 if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &value, &value_len) == FAILURE) {
44 }
45
46 nodep = xmlNewText(BAD_CAST value);
47
48 if (!nodep) {
51 }
52
53 intern = Z_DOMOBJ_P(ZEND_THIS);
54 oldnode = dom_object_get_node(intern);
55 if (oldnode != NULL) {
56 php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
57 }
58 php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
59}
60/* }}} end DOMText::__construct */
61
62/* {{{ wholeText string
63readonly=yes
64URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Text3-wholeText
65Since: DOM Level 3
66*/
68{
69 DOM_PROP_NODE(xmlNodePtr, node, obj);
70
71 smart_str str = {0};
72
73 /* Find starting text node */
74 while (node->prev && ((node->prev->type == XML_TEXT_NODE) || (node->prev->type == XML_CDATA_SECTION_NODE))) {
75 node = node->prev;
76 }
77
78 /* concatenate all adjacent text and cdata nodes */
79 while (node && ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE))) {
80 if (node->content) {
81 smart_str_appends(&str, (const char *) node->content);
82 }
83 node = node->next;
84 }
85
86 ZVAL_STR(retval, smart_str_extract(&str));
87
88 return SUCCESS;
89}
90
91/* }}} */
92
93/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-38853C1D
94Modern spec URL: https://dom.spec.whatwg.org/#dom-text-splittext
95Since:
96*/
97PHP_METHOD(DOMText, splitText)
98{
99 zval *id;
100 xmlChar *first;
101 xmlChar *second;
102 xmlNodePtr node;
103 xmlNodePtr nnode;
105 int length;
106 dom_object *intern;
107
108 id = ZEND_THIS;
111 }
112 DOM_GET_OBJ(node, id, xmlNodePtr, intern);
113
114 if (offset < 0) {
115 zend_argument_value_error(1, "must be greater than or equal to 0");
117 }
118
119 const xmlChar *cur = php_dom_get_content_or_empty(node);
120 length = xmlUTF8Strlen(cur);
121
122 if (ZEND_LONG_INT_OVFL(offset) || (int)offset > length) {
123 if (php_dom_follow_spec_intern(intern)) {
124 php_dom_throw_error(INDEX_SIZE_ERR, /* strict */ true);
125 }
127 }
128
129 first = xmlUTF8Strndup(cur, (int)offset);
130 second = xmlUTF8Strsub(cur, (int)offset, (int)(length - offset));
131
132 xmlNodeSetContent(node, first);
133 nnode = xmlNewDocText(node->doc, second);
134
135 xmlFree(first);
136 xmlFree(second);
137
138 if (nnode == NULL) {
139 php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
141 }
142
143 if (node->parent != NULL) {
144 nnode->type = XML_ELEMENT_NODE;
145 xmlAddNextSibling(node, nnode);
146 nnode->type = XML_TEXT_NODE;
147 }
148
149 php_dom_create_object(nnode, return_value, intern);
150}
151/* }}} end dom_text_split_text */
152
153/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Text3-isWhitespaceInElementContent
154Since: DOM Level 3
155*/
156PHP_METHOD(DOMText, isWhitespaceInElementContent)
157{
158 zval *id;
159 xmlNodePtr node;
160 dom_object *intern;
161
162 id = ZEND_THIS;
165 }
166 DOM_GET_OBJ(node, id, xmlNodePtr, intern);
167
168 if (xmlIsBlankNode(node)) {
170 } else {
172 }
173}
174/* }}} end dom_text_is_whitespace_in_element_content */
175
176#endif
zend_result dom_text_whole_text_read(dom_object *obj, zval *retval)
#define DOM_PROP_NODE(type, name, obj)
void php_dom_throw_error(dom_exception_code error_code, bool strict_error)
@ INVALID_STATE_ERR
@ INDEX_SIZE_ERR
zend_long offset
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
#define PHP_METHOD
Definition php.h:365
#define DOM_GET_OBJ(__ptr, __id, __prtype, __intern)
Definition php_dom.h:237
const XML_TEXT_NODE
const XML_ELEMENT_NODE
const XML_CDATA_SECTION_NODE
PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj)
struct _dom_object dom_object
#define Z_DOMOBJ_P(zv)
Definition xml_common.h:36
PHP_DOM_EXPORT bool php_dom_create_object(xmlNodePtr obj, zval *return_value, dom_object *domobj)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
Definition zend_API.c:1300
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:433
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define RETURN_FALSE
Definition zend_API.h:1058
#define zend_parse_parameters_none()
Definition zend_API.h:353
#define RETURN_THROWS()
Definition zend_API.h:1060
#define ZEND_THIS
Definition zend_API.h:523
#define RETURN_TRUE
Definition zend_API.h:1059
struct _zval_struct zval
int32_t zend_long
Definition zend_long.h:42
#define ZEND_LONG_INT_OVFL(zlong)
#define ZVAL_STR(z, s)
@ FAILURE
Definition zend_types.h:61
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
zval retval
zval * return_value
value