summaryrefslogtreecommitdiff
path: root/ext/intl/intl_convert.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2015-07-01 13:26:39 +0300
committerDmitry Stogov <dmitry@zend.com>2015-07-01 13:26:39 +0300
commitf7b6de5b5eea4554a1eb3e7bfc64877567693985 (patch)
tree0f271798439b3c8c1982f52b5b73073849c7433c /ext/intl/intl_convert.c
parent53403fe56d7c80eff75a3bd1bfd014aa33ac457b (diff)
downloadphp-git-f7b6de5b5eea4554a1eb3e7bfc64877567693985.tar.gz
Cleanup (avoid string reallocations)
Diffstat (limited to 'ext/intl/intl_convert.c')
-rw-r--r--ext/intl/intl_convert.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/ext/intl/intl_convert.c b/ext/intl/intl_convert.c
index 51537062f5..2ae43fbb96 100644
--- a/ext/intl/intl_convert.c
+++ b/ext/intl/intl_convert.c
@@ -109,21 +109,18 @@ void intl_convert_utf8_to_utf16(
/* {{{ intl_convert_utf16_to_utf8
* Convert given string from UTF-16 to UTF-8.
*
- * @param target Where to place the result.
- * @param target_len Result length.
* @param source String to convert.
* @param source_len Length of the source string.
* @param status Conversion status.
*
- * @return void This function does not return anything.
+ * @return zend_string
*/
-void intl_convert_utf16_to_utf8(
- char** target, size_t* target_len,
+zend_string* intl_convert_utf16_to_utf8(
const UChar* src, int32_t src_len,
UErrorCode* status )
{
- char* dst_buf = NULL;
- int32_t dst_len;
+ zend_string* dst;
+ int32_t dst_len;
/* Determine required destination buffer size (pre-flighting). */
*status = U_ZERO_ERROR;
@@ -134,26 +131,25 @@ void intl_convert_utf16_to_utf8(
* (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty).
*/
if( *status != U_BUFFER_OVERFLOW_ERROR && *status != U_STRING_NOT_TERMINATED_WARNING )
- return;
+ return NULL;
/* Allocate memory for the destination buffer (it will be zero-terminated). */
- dst_buf = emalloc( dst_len+1 );
+ dst = zend_string_alloc(dst_len, 0);
/* Convert source string from UTF-8 to UTF-16. */
*status = U_ZERO_ERROR;
- u_strToUTF8( dst_buf, dst_len, NULL, src, src_len, status );
+ u_strToUTF8( ZSTR_VAL(dst), dst_len, NULL, src, src_len, status );
if( U_FAILURE( *status ) )
{
- efree( dst_buf );
- return;
+ zend_string_free(dst);
+ return NULL;
}
/* U_STRING_NOT_TERMINATED_WARNING is OK for us => reset 'status'. */
*status = U_ZERO_ERROR;
- dst_buf[dst_len] = 0;
- *target = dst_buf;
- *target_len = (size_t)dst_len;
+ ZSTR_VAL(dst)[dst_len] = 0;
+ return dst;
}
/* }}} */