diff options
author | Rob Richards <rrichards@php.net> | 2004-09-08 10:15:41 +0000 |
---|---|---|
committer | Rob Richards <rrichards@php.net> | 2004-09-08 10:15:41 +0000 |
commit | ccb99d0a1e3e2240ad803436c34fd055feeb59cc (patch) | |
tree | 3a93f8a5e0d7a063ff81e7160586e3fdaf6cf952 | |
parent | 9ed4b04f6a43115424cfae684fd3d211e29d1a58 (diff) | |
download | php-git-ccb99d0a1e3e2240ad803436c34fd055feeb59cc.tar.gz |
implement php_libxml_xmlCheckUTF8
- workaround for pre libxml2-2.6.13 function
-rw-r--r-- | ext/libxml/libxml.c | 26 | ||||
-rw-r--r-- | ext/libxml/php_libxml.h | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 7a8b4d2d2c..8eac2eb8e5 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -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; diff --git a/ext/libxml/php_libxml.h b/ext/libxml/php_libxml.h index 5642abc627..9f7c96f2ed 100644 --- a/ext/libxml/php_libxml.h +++ b/ext/libxml/php_libxml.h @@ -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 */ |