File: collator_get_sort_key.phpt

package info (click to toggle)
php5 5.3.3-7%2Bsqueeze17
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 122,824 kB
  • ctags: 55,742
  • sloc: ansic: 633,963; php: 19,620; sh: 11,344; xml: 5,816; cpp: 2,400; yacc: 1,745; exp: 1,514; makefile: 1,019; pascal: 623; awk: 537; sql: 22
file content (97 lines) | stat: -rwxr-xr-x 1,941 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--TEST--
collator_get_sort_key()
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
--FILE--
<?php

/*
 * Get sort keys using various locales
 */
function sort_arrays( $locale, $data )
{
    $res_str = '';

    $coll = ut_coll_create( $locale );

	foreach($data as $value) {
		$res_val = ut_coll_get_sort_key( $coll, $value );
		$res_str .= "source: ".urlencode($value)."\n".
					"key: ".urlencode($res_val)."\n";
	}

    return $res_str;
}


function ut_main()
{
    $res_str = '';

    // Regular strings keys
    $test_params = array(
		'abc', 'abd', 'aaa', 
		'аа', 'а', 'z',
		'', null , '3',
        'y'  , 'i'  , 'k'
    );

    $res_str .= sort_arrays( 'en_US', $test_params );

    // Sort a non-ASCII array using ru_RU locale.
    $test_params = array(
		'абг', 'абв', 'жжж', 'эюя' 
    );

    $res_str .= sort_arrays( 'ru_RU', $test_params );

    // Sort an array using Lithuanian locale.
    $res_str .= sort_arrays( 'lt_LT', $test_params );

    return $res_str . "\n";
}

include_once( 'ut_common.inc' );
ut_run();
?>
--EXPECT--
source: abc
key: %29%2B-%01%07%01%07%00
source: abd
key: %29%2B%2F%01%07%01%07%00
source: aaa
key: %29%29%29%01%07%01%07%00
source: %D0%B0%D0%B0
key: _++%01%06%01%06%00
source: %D0%B0
key: _+%01%05%01%05%00
source: z
key: %5B%01%05%01%05%00
source: 
key: %01%01%00
source: 
key: %01%01%00
source: 3
key: %26%80%01%05%01%05%00
source: y
key: Y%01%05%01%05%00
source: i
key: 9%01%05%01%05%00
source: k
key: %3D%01%05%01%05%00
source: %D0%B0%D0%B1%D0%B3
key: _+%2C0%01%07%01%07%00
source: %D0%B0%D0%B1%D0%B2
key: _+%2C.%01%07%01%07%00
source: %D0%B6%D0%B6%D0%B6
key: _LLL%01%07%01%07%00
source: %D1%8D%D1%8E%D1%8F
key: %60%05%09%0B%01%07%01%07%00
source: %D0%B0%D0%B1%D0%B3
key: _+%2C0%01%07%01%07%00
source: %D0%B0%D0%B1%D0%B2
key: _+%2C.%01%07%01%07%00
source: %D0%B6%D0%B6%D0%B6
key: _LLL%01%07%01%07%00
source: %D1%8D%D1%8E%D1%8F
key: %60%05%09%0B%01%07%01%07%00