]> granicus.if.org Git - php/commitdiff
- str_pad(): Use u_countChar32() for codepoint counting, eumalloc/eurealloc() for...
authorRolland Santimano <rolland@php.net>
Fri, 9 Sep 2005 19:07:18 +0000 (19:07 +0000)
committerRolland Santimano <rolland@php.net>
Fri, 9 Sep 2005 19:07:18 +0000 (19:07 +0000)
ext/standard/string.c

index 29da37969106cfd8bfff18c1eee7d2e6a896a993..4f255d4d8e9634d73d80c4e98332474f55526097 100644 (file)
@@ -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));