From aa9de18ef5a0b2069140ce047f4648882cbcca74 Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Mon, 14 Aug 2006 21:04:50 +0000 Subject: [PATCH] Unicode support for str_split(). --- ext/standard/string.c | 23 ++++++++++++++--------- unicode-progress.txt | 4 +--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index e1e25024c2..e2e045e26e 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -6973,17 +6973,19 @@ PHP_FUNCTION(money_format) /* }}} */ #endif -/* {{{ proto array str_split(string str [, int split_length]) +/* {{{ proto array str_split(string str [, int split_length]) U Convert a string to an array. If split_length is specified, break the string down into chunks each split_length characters long. */ PHP_FUNCTION(str_split) { - char *str; + zstr str; int str_len; long split_length = 1; char *p; + zend_uchar str_type; int n_reg_segments; + int charsize = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &split_length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|l", &str, &str_len, &str_type, &split_length) == FAILURE) { return; } @@ -6995,20 +6997,23 @@ PHP_FUNCTION(str_split) array_init(return_value); if (split_length >= str_len) { - add_next_index_stringl(return_value, str, str_len, 1); + add_next_index_zstrl(return_value, str, str_len, str_type, 1); return; } n_reg_segments = floor(str_len / split_length); - p = str; + p = str.s; + if (str_type == IS_UNICODE) { + charsize = 2; + } while (n_reg_segments-- > 0) { - add_next_index_stringl(return_value, p, split_length, 1); - p += split_length; + add_next_index_zstrl(return_value, ZSTR(p), split_length, str_type, 1); + p += split_length * charsize; } - if (p != (str + str_len)) { - add_next_index_stringl(return_value, p, (str + str_len - p), 1); + if (p != (str.s + str_len * charsize)) { + add_next_index_zstrl(return_value, ZSTR(p), (str.s + str_len * charsize - p), str_type, 1); } } /* }}} */ diff --git a/unicode-progress.txt b/unicode-progress.txt index 0eef176a99..7196354252 100644 --- a/unicode-progress.txt +++ b/unicode-progress.txt @@ -49,9 +49,6 @@ ext/standard Params API, IS_UNICODE upgrade. Case-folding should be handled similar to stristr(). - str_split() - IS_UNICODE support, split on codepoint level. - str_word_count() Params API, IS_UNICODE support, using u_isalpha(), etc. @@ -190,6 +187,7 @@ ext/standard str_repeat() str_rot13() str_shuffle() + str_split() strcspn() strip_tags() stripcslashes() -- 2.40.0