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			$str_norm = ut_norm_normalize( $str, $form );
73			$error_code = intl_get_error_code();
74			$error_message = intl_get_error_message();
75
76			$str_hex = urlencode($str);
77			$str_norm_hex = urlencode($str_norm);
78			$res_str .= "'$str_hex' normalized to form '{$forms_str[$form]}' is '$str_norm_hex'"
79					 .	"\terror info: '$error_message' ($error_code)\n"
80					 .	"";
81
82			$is_norm = ut_norm_is_normalized( $str, $form );
83			$error_code = intl_get_error_code();
84			$error_message = intl_get_error_message();
85
86			$res_str .= "		is in form '{$forms_str[$form]}'? = " . ($is_norm ? "yes" : "no")
87					 .	"\terror info: '$error_message' ($error_code)\n"
88					 .	"";
89		}
90	}
91
92	return $res_str;
93}
94
95include_once( 'ut_common.inc' );
96ut_run();
97
98?>
99--EXPECT--
100'ABC' normalized to form 'UNORM_FORM_C' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
101		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
102'%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)
103		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
104'%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)
105		is in form 'UNORM_FORM_C'? = no	error info: 'U_ZERO_ERROR' (0)
106'%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)
107		is in form 'UNORM_FORM_C'? = no	error info: 'U_ZERO_ERROR' (0)
108'%EF%AC%81' normalized to form 'UNORM_FORM_C' is '%EF%AC%81'	error info: 'U_ZERO_ERROR' (0)
109		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
110'%E1%BA%9B' normalized to form 'UNORM_FORM_C' is '%E1%BA%9B'	error info: 'U_ZERO_ERROR' (0)
111		is in form 'UNORM_FORM_C'? = yes	error info: 'U_ZERO_ERROR' (0)
112'ABC' normalized to form 'UNORM_FORM_D' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
113		is in form 'UNORM_FORM_D'? = yes	error info: 'U_ZERO_ERROR' (0)
114'%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)
115		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
116'%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)
117		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
118'%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)
119		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
120'%EF%AC%81' normalized to form 'UNORM_FORM_D' is '%EF%AC%81'	error info: 'U_ZERO_ERROR' (0)
121		is in form 'UNORM_FORM_D'? = yes	error info: 'U_ZERO_ERROR' (0)
122'%E1%BA%9B' normalized to form 'UNORM_FORM_D' is '%C5%BF%CC%87'	error info: 'U_ZERO_ERROR' (0)
123		is in form 'UNORM_FORM_D'? = no	error info: 'U_ZERO_ERROR' (0)
124'ABC' normalized to form 'UNORM_FORM_KC' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
125		is in form 'UNORM_FORM_KC'? = yes	error info: 'U_ZERO_ERROR' (0)
126'%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)
127		is in form 'UNORM_FORM_KC'? = yes	error info: 'U_ZERO_ERROR' (0)
128'%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)
129		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
130'%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)
131		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
132'%EF%AC%81' normalized to form 'UNORM_FORM_KC' is 'fi'	error info: 'U_ZERO_ERROR' (0)
133		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
134'%E1%BA%9B' normalized to form 'UNORM_FORM_KC' is '%E1%B9%A1'	error info: 'U_ZERO_ERROR' (0)
135		is in form 'UNORM_FORM_KC'? = no	error info: 'U_ZERO_ERROR' (0)
136'ABC' normalized to form 'UNORM_FORM_KD' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
137		is in form 'UNORM_FORM_KD'? = yes	error info: 'U_ZERO_ERROR' (0)
138'%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)
139		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
140'%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)
141		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
142'%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)
143		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
144'%EF%AC%81' normalized to form 'UNORM_FORM_KD' is 'fi'	error info: 'U_ZERO_ERROR' (0)
145		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
146'%E1%BA%9B' normalized to form 'UNORM_FORM_KD' is 's%CC%87'	error info: 'U_ZERO_ERROR' (0)
147		is in form 'UNORM_FORM_KD'? = no	error info: 'U_ZERO_ERROR' (0)
148'ABC' normalized to form 'UNORM_NONE' is 'ABC'	error info: 'U_ZERO_ERROR' (0)
149		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
150'%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)
151		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
152'%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)
153		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
154'%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)
155		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
156'%EF%AC%81' normalized to form 'UNORM_NONE' is '%EF%AC%81'	error info: 'U_ZERO_ERROR' (0)
157		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
158'%E1%BA%9B' normalized to form 'UNORM_NONE' is '%E1%BA%9B'	error info: 'U_ZERO_ERROR' (0)
159		is in form 'UNORM_NONE'? = no	error info: 'normalizer_normalize: illegal normalization form: U_ILLEGAL_ARGUMENT_ERROR' (1)
160
161