2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 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_0.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
+----------------------------------------------------------------------+
20
/* $Id: characterdata.c,v 1.13.2.1 2004/11/18 19:55:00 rrichards Exp $ */
27
#if HAVE_LIBXML && HAVE_DOM
32
* class DOMCharacterData extends DOMNode
34
* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-FF21A306
38
zend_function_entry php_dom_characterdata_class_functions[] = {
39
PHP_FALIAS(substringData, dom_characterdata_substring_data, NULL)
40
PHP_FALIAS(appendData, dom_characterdata_append_data, NULL)
41
PHP_FALIAS(insertData, dom_characterdata_insert_data, NULL)
42
PHP_FALIAS(deleteData, dom_characterdata_delete_data, NULL)
43
PHP_FALIAS(replaceData, dom_characterdata_replace_data, NULL)
49
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-72AB8359
52
int dom_characterdata_data_read(dom_object *obj, zval **retval TSRMLS_DC)
57
nodep = dom_object_get_node(obj);
60
php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
66
if ((content = xmlNodeGetContent(nodep)) != NULL) {
67
ZVAL_STRING(*retval, content, 1);
70
ZVAL_EMPTY_STRING(*retval);
76
int dom_characterdata_data_write(dom_object *obj, zval *newval TSRMLS_DC)
81
nodep = dom_object_get_node(obj);
84
php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
88
if (newval->type != IS_STRING) {
89
if(newval->refcount > 1) {
91
zval_copy_ctor(&value_copy);
94
convert_to_string(newval);
97
xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
99
if (newval == &value_copy) {
110
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-7D61178C
113
int dom_characterdata_length_read(dom_object *obj, zval **retval TSRMLS_DC)
119
nodep = dom_object_get_node(obj);
122
php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
128
content = xmlNodeGetContent(nodep);
131
length = xmlUTF8Strlen(content);
135
ZVAL_LONG(*retval, length);
143
/* {{{ proto string dom_characterdata_substring_data(int offset, int count);
144
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6531BCCF
147
PHP_FUNCTION(dom_characterdata_substring_data)
157
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &id, dom_characterdata_class_entry, &offset, &count) == FAILURE) {
161
DOM_GET_OBJ(node, id, xmlNodePtr, intern);
163
cur = xmlNodeGetContent(node);
168
length = xmlUTF8Strlen(cur);
170
if (offset < 0 || count < 0 || offset > length) {
172
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
176
if ((offset + count) > length) {
177
count = length - offset;
180
substring = xmlUTF8Strsub(cur, offset, count);
184
RETVAL_STRING(substring, 1);
187
RETVAL_EMPTY_STRING();
190
/* }}} end dom_characterdata_substring_data */
193
/* {{{ proto void dom_characterdata_append_data(string arg);
194
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-32791A2F
197
PHP_FUNCTION(dom_characterdata_append_data)
205
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_characterdata_class_entry, &arg, &arg_len) == FAILURE) {
209
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
211
xmlTextConcat(nodep, arg, arg_len);
215
/* }}} end dom_characterdata_append_data */
218
/* {{{ proto void dom_characterdata_insert_data(int offset, string arg);
219
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-3EDB695F
222
PHP_FUNCTION(dom_characterdata_insert_data)
225
xmlChar *cur, *first, *second;
232
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols", &id, dom_characterdata_class_entry, &offset, &arg, &arg_len) == FAILURE) {
236
DOM_GET_OBJ(node, id, xmlNodePtr, intern);
238
cur = xmlNodeGetContent(node);
243
length = xmlUTF8Strlen(cur);
245
if (offset < 0 || offset > length) {
247
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
251
first = xmlUTF8Strndup(cur, offset);
252
second = xmlUTF8Strsub(cur, offset, length - offset);
255
xmlNodeSetContent(node, first);
256
xmlNodeAddContent(node, arg);
257
xmlNodeAddContent(node, second);
264
/* }}} end dom_characterdata_insert_data */
267
/* {{{ proto void dom_characterdata_delete_data(int offset, int count);
268
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-7C603781
271
PHP_FUNCTION(dom_characterdata_delete_data)
274
xmlChar *cur, *substring, *second;
280
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &id, dom_characterdata_class_entry, &offset, &count) == FAILURE) {
284
DOM_GET_OBJ(node, id, xmlNodePtr, intern);
286
cur = xmlNodeGetContent(node);
291
length = xmlUTF8Strlen(cur);
293
if (offset < 0 || count < 0 || offset > length) {
295
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
300
substring = xmlUTF8Strsub(cur, 0, offset);
305
if ((offset + count) > length) {
306
count = length - offset;
309
second = xmlUTF8Strsub(cur, offset + count, length - offset);
310
substring = xmlStrcat(substring, second);
312
xmlNodeSetContent(node, substring);
320
/* }}} end dom_characterdata_delete_data */
323
/* {{{ proto void dom_characterdata_replace_data(int offset, int count, string arg);
324
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-E5CBA7FB
327
PHP_FUNCTION(dom_characterdata_replace_data)
330
xmlChar *cur, *substring, *second = NULL;
337
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olls", &id, dom_characterdata_class_entry, &offset, &count, &arg, &arg_len) == FAILURE) {
341
DOM_GET_OBJ(node, id, xmlNodePtr, intern);
343
cur = xmlNodeGetContent(node);
348
length = xmlUTF8Strlen(cur);
350
if (offset < 0 || count < 0 || offset > length) {
352
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
357
substring = xmlUTF8Strsub(cur, 0, offset);
362
if ((offset + count) > length) {
363
count = length - offset;
366
if (offset < length) {
367
second = xmlUTF8Strsub(cur, offset + count, length - offset);
370
substring = xmlStrcat(substring, arg);
371
substring = xmlStrcat(substring, second);
373
xmlNodeSetContent(node, substring);
383
/* }}} end dom_characterdata_replace_data */