1--TEST--
2mb_str_split()  tests for the russian language
3--EXTENSIONS--
4mbstring
5--INI--
6output_handler=
7--FILE--
8<?php
9ini_set('include_path','.');
10include_once('common.inc');
11
12$string = "рай рай рай ";             /* 12 chars */
13$len = 12;
14$charset = [
15    "EUC-JP",
16    "CP866",
17    "KOI8-R",
18    "UTF-16BE",
19    "UTF-16LE",
20    "UTF-32BE",
21    "UTF-32LE",
22    "UTF-8"
23];
24
25
26foreach($charset as $cs){
27    $enc = mb_convert_encoding($string, $cs, "UTF-8");
28    $split = mb_str_split($enc, 1, $cs);
29
30
31    /* check chunks number */
32    for($i = 1; $i <= $len; ++$i){
33        $ceil = ceil($len / $i);
34        $cnt = count(mb_str_split($enc,$i,$cs));
35        if($ceil != $cnt){
36          echo "$cs WRONG CHUNKS NUMBER: expected/actual: $ceil/$cnt\n";
37        }
38    }
39
40    /* check content */
41    echo "$cs:";
42    for($i = 0; $i < $len; ++$i){
43        echo  " " . unpack("H*", $split[$i])[1];
44    }
45    echo "\n";
46}
47
48/* long string test */
49$size = 25000;
50$long = str_repeat($string, $size); /* 25k x 12 chars = 3e5 chars */
51$enc = mb_convert_encoding($long, "EUC-JP", "UTF-8");
52$array = mb_str_split($enc, $len, "EUC-JP");
53$count = count($array);
54
55/* check array size */
56if($size !== $count) printf("Long string splitting error: actual array size: %d expected: %d\n", $count, $size);
57
58/* compare initial string and last array element after splitting */
59$enc = mb_convert_encoding($string, "EUC-JP", "UTF-8");
60if(end($array) !== $enc){
61    printf("Long string splitting error:
62        last array element: %s expected: %s\n", unpack("H*", end($array))[1],unpack("H*", $enc)[1]);
63}
64
65?>
66--EXPECT--
67EUC-JP: a7e2 a7d1 a7db 20 a7e2 a7d1 a7db 20 a7e2 a7d1 a7db 20
68CP866: e0 a0 a9 20 e0 a0 a9 20 e0 a0 a9 20
69KOI8-R: d2 c1 ca 20 d2 c1 ca 20 d2 c1 ca 20
70UTF-16BE: 0440 0430 0439 0020 0440 0430 0439 0020 0440 0430 0439 0020
71UTF-16LE: 4004 3004 3904 2000 4004 3004 3904 2000 4004 3004 3904 2000
72UTF-32BE: 00000440 00000430 00000439 00000020 00000440 00000430 00000439 00000020 00000440 00000430 00000439 00000020
73UTF-32LE: 40040000 30040000 39040000 20000000 40040000 30040000 39040000 20000000 40040000 30040000 39040000 20000000
74UTF-8: d180 d0b0 d0b9 20 d180 d0b0 d0b9 20 d180 d0b0 d0b9 20
75