]> granicus.if.org Git - php/commitdiff
synchronize iconv_substr() behavior with substr()
authorAntony Dovgal <tony2001@php.net>
Mon, 12 Mar 2007 19:34:26 +0000 (19:34 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 12 Mar 2007 19:34:26 +0000 (19:34 +0000)
no MFB so far, since substr() changes are not MFBed either

ext/iconv/iconv.c
ext/iconv/tests/iconv_substr.phpt

index 4d66476094beec8624ff192a87c55609b939a9d0..398952a2c59e0a67e267f50e449829346c9013c1 100644 (file)
@@ -679,28 +679,30 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval,
                return err;
        }
        
-       /* normalize the offset and the length */
-       if (offset < 0) {
-               if ((offset += total_len) < 0) {
-                       offset = 0;
-               }
-       }
        if (len < 0) {
                if ((len += (total_len - offset)) < 0) {
-                       len = 0;
+                       return PHP_ICONV_ERR_SUCCESS;
+               }
+       }
+
+       if (offset < 0) {
+               if ((offset += total_len) < 0) {
+                       return PHP_ICONV_ERR_SUCCESS;
                }
        }
 
        if (offset >= total_len) {
                return PHP_ICONV_ERR_SUCCESS;
        }
-       
+
        if ((offset + len) > total_len) {
                /* trying to compute the length */
                len = total_len - offset;
        }
 
        if (len == 0) {
+               smart_str_appendl(pretval, "", 0);
+               smart_str_0(pretval);
                return PHP_ICONV_ERR_SUCCESS;
        }
        
@@ -1910,16 +1912,11 @@ PHP_FUNCTION(iconv_substr)
        err = _php_iconv_substr(&retval, str, str_len, offset, length, charset); 
        _php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC);
 
-       if (err == PHP_ICONV_ERR_SUCCESS && str != NULL) {
-               if (retval.c != NULL) {
-                       RETVAL_STRINGL(retval.c, retval.len, 0);
-               } else {
-                       RETVAL_EMPTY_STRING();
-               }
-       } else {
-               smart_str_free(&retval);
-               RETVAL_FALSE;
+       if (err == PHP_ICONV_ERR_SUCCESS && str != NULL && retval.c != NULL) {
+               RETURN_STRINGL(retval.c, retval.len, 0);
        }
+       smart_str_free(&retval);
+       RETURN_FALSE;
 }
 /* }}} */
 
index 5ee01d488a3f82fe8f421685f7c58bcbd5dda7e0..6ca545b2ea19cd1bcce9db2aecfb002002d17d11 100644 (file)
@@ -45,15 +45,15 @@ var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP", "ISO-2022-J
 a6a4a8a4aaa4ab
 a4aba4ada4afa4b1a4b3a4b5a4b7
 bool(false)
-string(0) ""
+bool(false)
 string(14) "This is a test"
 string(14) "This is a test"
 string(3) "est"
 string(3) "est"
 string(5) "This "
 string(5) "This "
-string(0) ""
-string(0) ""
-string(0) ""
-string(0) ""
+bool(false)
+bool(false)
+bool(false)
+bool(false)
 string(10) "¤Á¤Ï ISO-2"