From: Rolland Santimano Date: Fri, 9 Sep 2005 19:07:18 +0000 (+0000) Subject: - str_pad(): Use u_countChar32() for codepoint counting, eumalloc/eurealloc() for... X-Git-Tag: RELEASE_0_9_0~246 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05e365bab3c49506d2bcc6181b0c4ddec60fe6ae;p=php - str_pad(): Use u_countChar32() for codepoint counting, eumalloc/eurealloc() for Unicode mallocs. --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 29da379691..4f255d4d8e 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5394,10 +5394,7 @@ PHP_FUNCTION(str_pad) if (input_type == IS_UNICODE) { /* For Unicode, num_pad_chars/pad_length is number of codepoints */ i = 0; input_codepts = 0; - while (i < input_len) { - U16_FWD_1((UChar *)input, i, input_len); - input_codepts++; - } + input_codepts = u_countChar32((UChar *)input, input_len); num_pad_chars = pad_length - input_codepts; } else { num_pad_chars = pad_length - input_len; @@ -5439,7 +5436,7 @@ PHP_FUNCTION(str_pad) } if (input_type == IS_UNICODE) { - result = emalloc(UBYTES(input_len + num_pad_chars*2 + 1)); + result = eumalloc(input_len + num_pad_chars*2 + 1); } else { result = emalloc(input_len + num_pad_chars + 1); } @@ -5481,7 +5478,7 @@ PHP_FUNCTION(str_pad) result_len += zend_codepoint_to_uchar(ch, (UChar *)result + result_len); } *((UChar *)result + result_len) = 0; - result = erealloc(result, UBYTES(result_len+1)); + result = eurealloc(result, result_len+1); } else { for (i = 0; i < left_pad; i++) *((char *)result + result_len++) = *((char *)padstr + (i % padstr_len));