1--TEST--
2normalize()
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5--FILE--
6<?php
7
8/*
9 * Try normalization and test normalization
10 * with Procedural and Object methods.
11 */
12
13function ut_main()
14{
15	$res_str = '';
16
17	$forms = array(
18		Normalizer::FORM_C,
19		Normalizer::FORM_D,
20		Normalizer::FORM_KC,
21		Normalizer::FORM_KD,
22		Normalizer::NONE,
23	);
24
25	$forms_str = array (
26		Normalizer::FORM_C => 'UNORM_FORM_C',
27		Normalizer::FORM_D => 'UNORM_FORM_D',
28		Normalizer::FORM_KC => 'UNORM_FORM_KC',
29		Normalizer::FORM_KD => 'UNORM_FORM_KD',
30		Normalizer::NONE => 'UNORM_NONE',
31	);
32
33	/* just make sure all the form constants are defined as in the api spec */
34	if ( Normalizer::FORM_C != Normalizer::NFC ||
35		 Normalizer::FORM_D != Normalizer::NFD ||
36		 Normalizer::FORM_KC != Normalizer::NFKC ||
37		 Normalizer::FORM_KD != Normalizer::NFKD ||
38		 Normalizer::NONE == Normalizer::FORM_C ) {
39
40			$res_str .= "Invalid normalization form declarations!\n";
41	}
42
43	$char_a_diaeresis = "\xC3\xA4";	// 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4)
44	$char_a_ring = "\xC3\xA5";		// 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5)
45	$char_o_diaeresis = "\xC3\xB6";    // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6)
46
47	$char_angstrom_sign = "\xE2\x84\xAB"; // 'ANGSTROM SIGN' (U+212B)
48	$char_A_ring = "\xC3\x85";	// 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
49
50	$char_ohm_sign = "\xE2\x84\xA6";	// 'OHM SIGN' (U+2126)
51	$char_omega = "\xCE\xA9";  // 'GREEK CAPITAL LETTER OMEGA' (U+03A9)
52
53	$char_combining_ring_above = "\xCC\x8A";  // 'COMBINING RING ABOVE' (U+030A)
54
55	$char_fi_ligature = "\xEF\xAC\x81";  // 'LATIN SMALL LIGATURE FI' (U+FB01)
56
57	$char_long_s_dot = "\xE1\xBA\x9B";	// 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B)
58
59	$strs = array(
60		'ABC',
61		$char_a_diaeresis . '||' . $char_a_ring . '||' . $char_o_diaeresis,
62		$char_angstrom_sign . '||' . $char_A_ring . '||' . 'A' . $char_combining_ring_above,
63		$char_ohm_sign . '||' . $char_omega,
64		$char_fi_ligature,
65		$char_long_s_dot,
66	);
67
68	foreach( $forms as $form )
69	{
70		foreach( $strs as $str )
71		{
72			if (Normalizer::NONE == $form) {
73				/* Hide deprecation warning. */
74				$str_norm = @ut_norm_normalize( $str, $form );
75			} else {
76				$str_norm = ut_norm_normalize( $str, $form );
77			}
78			$error_code = intl_get_error_code();
79			$error_message = intl_get_error_message();
80
81			$str_hex = urlencode($str);
82			$str_norm_hex = urlencode($str_norm);
83			$res_str .= "'$str_hex' normalized to form '{$forms_str[$form]}' is '$str_norm_hex'"
84					 .	"\terror info: '$error_message' ($error_code)\n"
85					 .	"";
86
87			$is_norm = ut_norm_is_normalized( $str, $form );
88			$error_code = intl_get_error_code();
89			$error_message = intl_get_error_message();
90
91			$res_str .= "		is in form '{$forms_str[$form]}'? = " . ($is_norm ? "yes" : "no")
92					 .	"\terror info: '$error_message' ($error_code)\n"
93					 .	"";
94		}
95	}
96
97	return $res_str;
98}
99
100include_once( 'ut_common.inc' );
101ut_run();
102
103?>
104--EXPECT--
105'ABC' normalized to form 'UNORM_FORM_C' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
106		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
107'%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6' normalized to form 'UNORM_FORM_C' is '%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6'	error info: 'U_ZERO_ERROR' (0)
108		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
109'%E2%84%AB%7C%7C%C3%85%7C%7CA%CC%8A' normalized to form 'UNORM_FORM_C' is '%C3%85%7C%7C%C3%85%7C%7C%C3%85'	error info: 'U_ZERO_ERROR' (0)
110		is in form 'UNORM_FORM_C'? = no	error info: 'U_ZERO_ERROR' (0)
111'%E2%84%A6%7C%7C%CE%A9' normalized to form 'UNORM_FORM_C' is '%CE%A9%7C%7C%CE%A9'	error info: 'U_ZERO_ERROR' (0)
112		is in form 'UNORM_FORM_C'? = no	error info: 'U_ZERO_ERROR' (0)
113'%EF%AC%81' normalized to form 'UNORM_FORM_C' is '%EF%AC%81'	error info: 'U_ZERO_ERROR' (0)
114		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
115'%E1%BA%9B' normalized to form 'UNORM_FORM_C' is '%E1%BA%9B'	error info: 'U_ZERO_ERROR' (0)
116		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
117'ABC' normalized to form 'UNORM_FORM_D' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
118		is in form 'UNORM_FORM_D'? = yes	error info: 'U_ZERO_ERROR' (0)
119'%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6' normalized to form 'UNORM_FORM_D' is 'a%CC%88%7C%7Ca%CC%8A%7C%7Co%CC%88'	error info: 'U_ZERO_ERROR' (0)
120		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
121'%E2%84%AB%7C%7C%C3%85%7C%7CA%CC%8A' normalized to form 'UNORM_FORM_D' is 'A%CC%8A%7C%7CA%CC%8A%7C%7CA%CC%8A'	error info: 'U_ZERO_ERROR' (0)
122		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
123'%E2%84%A6%7C%7C%CE%A9' normalized to form 'UNORM_FORM_D' is '%CE%A9%7C%7C%CE%A9'	error info: 'U_ZERO_ERROR' (0)
124		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
125'%EF%AC%81' normalized to form 'UNORM_FORM_D' is '%EF%AC%81'	error info: 'U_ZERO_ERROR' (0)
126		is in form 'UNORM_FORM_D'? = yes	error info: 'U_ZERO_ERROR' (0)
127'%E1%BA%9B' normalized to form 'UNORM_FORM_D' is '%C5%BF%CC%87'	error info: 'U_ZERO_ERROR' (0)
128		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
129'ABC' normalized to form 'UNORM_FORM_KC' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
130		is in form 'UNORM_FORM_KC'? = yes	error info: 'U_ZERO_ERROR' (0)
131'%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6' normalized to form 'UNORM_FORM_KC' is '%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6'	error info: 'U_ZERO_ERROR' (0)
132		is in form 'UNORM_FORM_KC'? = yes	error info: 'U_ZERO_ERROR' (0)
133'%E2%84%AB%7C%7C%C3%85%7C%7CA%CC%8A' normalized to form 'UNORM_FORM_KC' is '%C3%85%7C%7C%C3%85%7C%7C%C3%85'	error info: 'U_ZERO_ERROR' (0)
134		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
135'%E2%84%A6%7C%7C%CE%A9' normalized to form 'UNORM_FORM_KC' is '%CE%A9%7C%7C%CE%A9'	error info: 'U_ZERO_ERROR' (0)
136		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
137'%EF%AC%81' normalized to form 'UNORM_FORM_KC' is 'fi'	error info: 'U_ZERO_ERROR' (0)
138		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
139'%E1%BA%9B' normalized to form 'UNORM_FORM_KC' is '%E1%B9%A1'	error info: 'U_ZERO_ERROR' (0)
140		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
141'ABC' normalized to form 'UNORM_FORM_KD' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
142		is in form 'UNORM_FORM_KD'? = yes	error info: 'U_ZERO_ERROR' (0)
143'%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6' normalized to form 'UNORM_FORM_KD' is 'a%CC%88%7C%7Ca%CC%8A%7C%7Co%CC%88'	error info: 'U_ZERO_ERROR' (0)
144		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
145'%E2%84%AB%7C%7C%C3%85%7C%7CA%CC%8A' normalized to form 'UNORM_FORM_KD' is 'A%CC%8A%7C%7CA%CC%8A%7C%7CA%CC%8A'	error info: 'U_ZERO_ERROR' (0)
146		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
147'%E2%84%A6%7C%7C%CE%A9' normalized to form 'UNORM_FORM_KD' is '%CE%A9%7C%7C%CE%A9'	error info: 'U_ZERO_ERROR' (0)
148		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
149'%EF%AC%81' normalized to form 'UNORM_FORM_KD' is 'fi'	error info: 'U_ZERO_ERROR' (0)
150		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
151'%E1%BA%9B' normalized to form 'UNORM_FORM_KD' is 's%CC%87'	error info: 'U_ZERO_ERROR' (0)
152		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
153'ABC' normalized to form 'UNORM_NONE' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
154		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
155'%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6' normalized to form 'UNORM_NONE' is '%C3%A4%7C%7C%C3%A5%7C%7C%C3%B6'	error info: 'U_ZERO_ERROR' (0)
156		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
157'%E2%84%AB%7C%7C%C3%85%7C%7CA%CC%8A' normalized to form 'UNORM_NONE' is '%E2%84%AB%7C%7C%C3%85%7C%7CA%CC%8A'	error info: 'U_ZERO_ERROR' (0)
158		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
159'%E2%84%A6%7C%7C%CE%A9' normalized to form 'UNORM_NONE' is '%E2%84%A6%7C%7C%CE%A9'	error info: 'U_ZERO_ERROR' (0)
160		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
161'%EF%AC%81' normalized to form 'UNORM_NONE' is '%EF%AC%81'	error info: 'U_ZERO_ERROR' (0)
162		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
163'%E1%BA%9B' normalized to form 'UNORM_NONE' is '%E1%BA%9B'	error info: 'U_ZERO_ERROR' (0)
164		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
165