]> granicus.if.org Git - php/commitdiff
use the new 's&' parameter type and simplify the code
authorNuno Lopes <nlopess@php.net>
Fri, 4 May 2007 17:45:56 +0000 (17:45 +0000)
committerNuno Lopes <nlopess@php.net>
Fri, 4 May 2007 17:45:56 +0000 (17:45 +0000)
ext/tidy/tests/007.phpt
ext/tidy/tidy.c

index d12d37cd626c422a2e184d422bee6fd961cb0ba8..fb3b1fece620fb3204df83046c06d5177f0b57c7 100644 (file)
@@ -36,5 +36,5 @@ Current Value of 'tab-size': int(8)
 Warning: tidy::getOpt(): Unknown Tidy Configuration Option 'bogus-opt' in %s007.php on line 10
 bool(false)
 
-Warning: tidy_getopt(): Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received in %s007.php on line 11
+Warning: Could not convert Unicode string to binary string (converter US-ASCII failed on character {U+00E0} at offset 17) in %s007.php on line 11
 bool(false)
index f79990982a231d24d893d8577cc11447b87de161..a5fadf76800a1164880ecc4ab9937006f053300c 100644 (file)
@@ -1173,38 +1173,27 @@ static int php_tidy_output_handler(void **nothing, php_output_context *output_co
    Parse a document stored in a string */
 static PHP_FUNCTION(tidy_parse_string)
 {
-       zstr input, enc = NULL_ZSTR;
-       zend_uchar input_type, enc_type = IS_STRING;
+       zstr input;
+       char *enc = NULL;
+       zend_uchar input_type;
        int input_len, enc_len;
        zval **options = NULL;
        PHPTidyObj *obj;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|Zt", &input, &input_len, &input_type, &options, &enc, &enc_len, &enc_type) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|Zs&", &input, &input_len, &input_type, &options, &enc, &enc_len, UG(ascii_conv)) == FAILURE) {
                RETURN_FALSE;
        }
 
-       if (enc_type != IS_STRING) {
-               enc.s = zend_unicode_to_ascii(enc.u, enc_len TSRMLS_CC);
-               if (!enc.s) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
-                       RETURN_FALSE;
-               }
-       }
-
        tidy_instanciate(tidy_ce_doc, return_value TSRMLS_CC);
        obj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC);
 
        TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options);
 
-       if (php_tidy_parse_string(obj, input.s, input_len, enc.s TSRMLS_CC) == FAILURE) {
+       if (php_tidy_parse_string(obj, input.s, input_len, enc TSRMLS_CC) == FAILURE) {
                zval_dtor(return_value);
                INIT_ZVAL(*return_value);
                RETVAL_FALSE;
        }
-
-       if (enc_type != IS_STRING) {
-               efree(enc.s);
-       }
 }
 /* }}} */
 
@@ -1339,48 +1328,31 @@ static PHP_FUNCTION(tidy_get_release)
 static PHP_FUNCTION(tidy_get_opt_doc)
 {
        PHPTidyObj *obj;
-       char *optval;
-       zstr optname;
-       zend_uchar optname_type;
+       char *optval, *optname;
        int optname_len;
        TidyOption opt;
 
        TIDY_SET_CONTEXT;
 
        if (object) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &optname, &optname_len, &optname_type) == FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&", &optname, &optname_len, UG(ascii_conv)) == FAILURE) {
                        RETURN_FALSE;
                }
        } else {
-               if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, NULL, "Ot", &object, tidy_ce_doc, &optname, &optname_len, &optname_type) == FAILURE) {
-                       RETURN_FALSE;
-               }
-       }
-
-       if (optname_type != IS_STRING) {
-               optname.s = zend_unicode_to_ascii(optname.u, optname_len TSRMLS_CC);
-               if (!optname.s) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
+               if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, NULL, "Os&", &object, tidy_ce_doc, &optname, &optname_len, UG(ascii_conv)) == FAILURE) {
                        RETURN_FALSE;
                }
        }
 
        obj = (PHPTidyObj *) zend_object_store_get_object(object TSRMLS_CC);
 
-       opt = tidyGetOptionByName(obj->ptdoc->doc, optname.s);
+       opt = tidyGetOptionByName(obj->ptdoc->doc, optname);
 
        if (!opt) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname.s);
-               if (optname_type != IS_STRING) {
-                       efree(optname.s);
-               }
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname);
                RETURN_FALSE;
        }
 
-       if (optname_type != IS_STRING) {
-               efree(optname.s);
-       }
-
        if ( (optval = (char *) tidyOptGetDoc(obj->ptdoc->doc, opt)) ) {
                RETURN_ASCII_STRING(optval, 1);
        }
@@ -1515,49 +1487,32 @@ static PHP_FUNCTION(tidy_config_count)
 static PHP_FUNCTION(tidy_getopt)
 {  
        PHPTidyObj *obj;
-       zstr optname;
-       void *optval;
+       void *optval, *optname;
        int optname_len;
        TidyOption opt;
        TidyOptionType optt;
-       zend_uchar optname_type;
 
        TIDY_SET_CONTEXT;
 
        if (object) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &optname, &optname_len, &optname_type) == FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&", &optname, &optname_len, UG(ascii_conv)) == FAILURE) {
                        RETURN_FALSE;
                }
        } else {
-               if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, NULL, "Ot", &object, tidy_ce_doc, &optname, &optname_len, &optname_type) == FAILURE) {
-                       RETURN_FALSE;
-               }
-       }
-
-       if (optname_type != IS_STRING) {
-               optname.s = zend_unicode_to_ascii(optname.u, optname_len TSRMLS_CC);
-               if (!optname.s) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
+               if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, NULL, "Os&", &object, tidy_ce_doc, &optname, &optname_len, UG(ascii_conv)) == FAILURE) {
                        RETURN_FALSE;
                }
        }
 
        obj = (PHPTidyObj *) zend_object_store_get_object(object TSRMLS_CC);
 
-       opt = tidyGetOptionByName(obj->ptdoc->doc, optname.s);
+       opt = tidyGetOptionByName(obj->ptdoc->doc, optname);
 
        if (!opt) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname.s);
-               if (optname_type != IS_STRING) {
-                       efree(optname.s);
-               }
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname);
                RETURN_FALSE;
        }
 
-       if (optname_type != IS_STRING) {
-               efree(optname.s);
-       }
-
        optval = php_tidy_get_opt_val(obj->ptdoc, opt, &optt TSRMLS_CC);
        switch (optt) {
                case TidyString: