]> granicus.if.org Git - php/commitdiff
Unicode support for str_split().
authorAndrei Zmievski <andrei@php.net>
Mon, 14 Aug 2006 21:04:50 +0000 (21:04 +0000)
committerAndrei Zmievski <andrei@php.net>
Mon, 14 Aug 2006 21:04:50 +0000 (21:04 +0000)
ext/standard/string.c
unicode-progress.txt

index e1e25024c228a527e33aa160f955757658b380d7..e2e045e26e43e7485cf0f5ab028cbcc06c2c45cc 100644 (file)
@@ -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);
        }
 }
 /* }}} */
index 0eef176a99e7e6a5eef421380373725be5d69ce4..7196354252e5ca7bd2472091eab340898a61be5d 100644 (file)
@@ -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()