summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Dovgal <tony2001@php.net>2007-03-12 19:34:26 +0000
committerAntony Dovgal <tony2001@php.net>2007-03-12 19:34:26 +0000
commit5088614ea1bb21a76216ce8a8a573183534fcf9f (patch)
tree99947719f7374b4d2902fd3d7e212c09ad0f525e
parentab699d03bc841f14718b4563bd50288168473640 (diff)
downloadphp-git-5088614ea1bb21a76216ce8a8a573183534fcf9f.tar.gz
synchronize iconv_substr() behavior with substr()
no MFB so far, since substr() changes are not MFBed either
-rw-r--r--ext/iconv/iconv.c31
-rw-r--r--ext/iconv/tests/iconv_substr.phpt10
2 files changed, 19 insertions, 22 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 4d66476094..398952a2c5 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -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;
}
/* }}} */
diff --git a/ext/iconv/tests/iconv_substr.phpt b/ext/iconv/tests/iconv_substr.phpt
index 5ee01d488a..6ca545b2ea 100644
--- a/ext/iconv/tests/iconv_substr.phpt
+++ b/ext/iconv/tests/iconv_substr.phpt
@@ -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"