]> granicus.if.org Git - php/commitdiff
add splitText()
authorSterling Hughes <sterling@php.net>
Fri, 6 Jun 2003 20:10:05 +0000 (20:10 +0000)
committerSterling Hughes <sterling@php.net>
Fri, 6 Jun 2003 20:10:05 +0000 (20:10 +0000)
never has such a complex process been endured for such a simple function
libxml makes me queasy right now :)

ext/dom/text.c

index ddbbb73559035c595486fa7b5355769b64add224..5a1fcc71b87fc4d4988448d66d11461401588a27 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "php.h"
 #include "php_dom.h"
-
+#include "dom_ce.h"
 
 /*
 * class domtext extends domcharacterdata 
@@ -97,7 +97,49 @@ Since:
 */
 PHP_FUNCTION(dom_text_split_text)
 {
- DOM_NOT_IMPLEMENTED();
+       zval       *id;
+       xmlChar    *cur;
+       xmlChar    *first;
+       xmlChar    *second;
+       xmlNodePtr  node;
+       xmlNodePtr  nnode;
+       long        offset;
+       int         ret;
+       int         length;
+
+       DOM_GET_THIS_OBJ(node, getThis(), xmlNodePtr);
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &offset) == FAILURE) {
+               return;
+       }
+
+       if (node->type != XML_TEXT_NODE) {
+               RETURN_FALSE;
+       }
+
+       cur = xmlNodeListGetString(node->doc, node, 1);
+       if (cur == NULL) {
+               RETURN_FALSE;
+       }
+       length = xmlStrlen(cur);
+
+       if (offset > length || offset < 0) {
+               RETURN_FALSE;
+       }
+
+       first = xmlStrndup(cur, offset);
+       second = xmlStrdup(cur + offset);
+       
+       xmlFree(cur);
+
+       xmlNodeSetContentLen(node, first, offset);
+       nnode = xmlNewText(second);
+
+       nnode->type = XML_ELEMENT_NODE;
+       xmlAddNextSibling(node, nnode);
+       nnode->type = XML_TEXT_NODE;
+       
+       return_value = php_dom_create_object(nnode, &ret, NULL, return_value TSRMLS_CC);
 }
 /* }}} end dom_text_split_text */