]> granicus.if.org Git - php/commitdiff
MFH: implement php_libxml_xmlCheckUTF8
authorRob Richards <rrichards@php.net>
Wed, 8 Sep 2004 10:16:57 +0000 (10:16 +0000)
committerRob Richards <rrichards@php.net>
Wed, 8 Sep 2004 10:16:57 +0000 (10:16 +0000)
 - workaround for <= libxml2-2.6.13 function

ext/libxml/libxml.c
ext/libxml/php_libxml.h

index f9564c753a9d01ae6f15ff6b497d975058b504b0..72bef55ad9476e941788ea24c2058a2a6e837211 100644 (file)
@@ -505,6 +505,32 @@ PHP_FUNCTION(libxml_set_streams_context)
 
 
 /* {{{ Common functions shared by extensions */
+int php_libxml_xmlCheckUTF8(const unsigned char *s)
+{
+       int i;
+       unsigned char c;
+
+       for (i = 0; (c = s[i++]);) {
+               if ((c & 0x80) == 0) {
+               } else if ((c & 0xe0) == 0xc0) {
+                       if ((s[i++] & 0xc0) != 0x80) {
+                               return 0;
+                       }
+               } else if ((c & 0xf0) == 0xe0) {
+                       if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
+                               return 0;
+                       }
+               } else if ((c & 0xf8) == 0xf0) {
+                       if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
+                               return 0;
+                       }
+               } else {
+                       return 0;
+               }
+       }
+       return 1;
+}
+
 int php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function)
 {
        php_libxml_func_handler export_hnd;
index 5642abc627e858862a9a5af115bb29b6ef5d8a3a..9f7c96f2edc1751ce3573561304139e5438804b0 100644 (file)
@@ -80,6 +80,7 @@ void php_libxml_node_decrement_resource(php_libxml_node_object *object TSRMLS_DC
 PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...);
 void php_libxml_ctx_warning(void *ctx, const char *msg, ...);
 void php_libxml_ctx_error(void *ctx, const char *msg, ...);
+PHP_LIBXML_API int php_libxml_xmlCheckUTF8(const unsigned char *s);
 
 #endif /* HAVE_LIBXML */