1--TEST-- 2normalize() 3--EXTENSIONS-- 4intl 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 ); 23 24 $forms_str = array ( 25 Normalizer::FORM_C => 'UNORM_FORM_C', 26 Normalizer::FORM_D => 'UNORM_FORM_D', 27 Normalizer::FORM_KC => 'UNORM_FORM_KC', 28 Normalizer::FORM_KD => 'UNORM_FORM_KD', 29 ); 30 31 /* just make sure all the form constants are defined as in the api spec */ 32 if ( Normalizer::FORM_C != Normalizer::NFC || 33 Normalizer::FORM_D != Normalizer::NFD || 34 Normalizer::FORM_KC != Normalizer::NFKC || 35 Normalizer::FORM_KD != Normalizer::NFKD) { 36 37 $res_str .= "Invalid normalization form declarations!\n"; 38 } 39 40 $char_a_diaeresis = "\xC3\xA4"; // 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4) 41 $char_a_ring = "\xC3\xA5"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) 42 $char_o_diaeresis = "\xC3\xB6"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) 43 44 $char_angstrom_sign = "\xE2\x84\xAB"; // 'ANGSTROM SIGN' (U+212B) 45 $char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5) 46 47 $char_ohm_sign = "\xE2\x84\xA6"; // 'OHM SIGN' (U+2126) 48 $char_omega = "\xCE\xA9"; // 'GREEK CAPITAL LETTER OMEGA' (U+03A9) 49 50 $char_combining_ring_above = "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A) 51 52 $char_fi_ligature = "\xEF\xAC\x81"; // 'LATIN SMALL LIGATURE FI' (U+FB01) 53 54 $char_long_s_dot = "\xE1\xBA\x9B"; // 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B) 55 56 $strs = array( 57 'ABC', 58 $char_a_diaeresis . '||' . $char_a_ring . '||' . $char_o_diaeresis, 59 $char_angstrom_sign . '||' . $char_A_ring . '||' . 'A' . $char_combining_ring_above, 60 $char_ohm_sign . '||' . $char_omega, 61 $char_fi_ligature, 62 $char_long_s_dot, 63 ); 64 65 foreach( $forms as $form ) 66 { 67 foreach( $strs as $str ) 68 { 69 $str_norm = ut_norm_normalize( $str, $form ); 70 $error_code = intl_get_error_code(); 71 $error_message = intl_get_error_message(); 72 73 $str_hex = urlencode($str); 74 $str_norm_hex = urlencode($str_norm); 75 $res_str .= "'$str_hex' normalized to form '{$forms_str[$form]}' is '$str_norm_hex'" 76 . "\terror info: '$error_message' ($error_code)\n" 77 . ""; 78 79 $is_norm = ut_norm_is_normalized( $str, $form ); 80 $error_code = intl_get_error_code(); 81 $error_message = intl_get_error_message(); 82 83 $res_str .= " is in form '{$forms_str[$form]}'? = " . ($is_norm ? "yes" : "no") 84 . "\terror info: '$error_message' ($error_code)\n" 85 . ""; 86 } 87 } 88 89 return $res_str; 90} 91 92include_once( 'ut_common.inc' ); 93ut_run(); 94 95?> 96--EXPECT-- 97'ABC' normalized to form 'UNORM_FORM_C' is 'ABC' error info: 'U_ZERO_ERROR' (0) 98 is in form 'UNORM_FORM_C'? = yes error info: 'U_ZERO_ERROR' (0) 99'%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) 100 is in form 'UNORM_FORM_C'? = yes error info: 'U_ZERO_ERROR' (0) 101'%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) 102 is in form 'UNORM_FORM_C'? = no error info: 'U_ZERO_ERROR' (0) 103'%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) 104 is in form 'UNORM_FORM_C'? = no error info: 'U_ZERO_ERROR' (0) 105'%EF%AC%81' normalized to form 'UNORM_FORM_C' is '%EF%AC%81' error info: 'U_ZERO_ERROR' (0) 106 is in form 'UNORM_FORM_C'? = yes error info: 'U_ZERO_ERROR' (0) 107'%E1%BA%9B' normalized to form 'UNORM_FORM_C' is '%E1%BA%9B' error info: 'U_ZERO_ERROR' (0) 108 is in form 'UNORM_FORM_C'? = yes error info: 'U_ZERO_ERROR' (0) 109'ABC' normalized to form 'UNORM_FORM_D' is 'ABC' error info: 'U_ZERO_ERROR' (0) 110 is in form 'UNORM_FORM_D'? = yes error info: 'U_ZERO_ERROR' (0) 111'%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) 112 is in form 'UNORM_FORM_D'? = no error info: 'U_ZERO_ERROR' (0) 113'%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) 114 is in form 'UNORM_FORM_D'? = no error info: 'U_ZERO_ERROR' (0) 115'%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) 116 is in form 'UNORM_FORM_D'? = no error info: 'U_ZERO_ERROR' (0) 117'%EF%AC%81' normalized to form 'UNORM_FORM_D' is '%EF%AC%81' error info: 'U_ZERO_ERROR' (0) 118 is in form 'UNORM_FORM_D'? = yes error info: 'U_ZERO_ERROR' (0) 119'%E1%BA%9B' normalized to form 'UNORM_FORM_D' is '%C5%BF%CC%87' error info: 'U_ZERO_ERROR' (0) 120 is in form 'UNORM_FORM_D'? = no error info: 'U_ZERO_ERROR' (0) 121'ABC' normalized to form 'UNORM_FORM_KC' is 'ABC' error info: 'U_ZERO_ERROR' (0) 122 is in form 'UNORM_FORM_KC'? = yes error info: 'U_ZERO_ERROR' (0) 123'%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) 124 is in form 'UNORM_FORM_KC'? = yes error info: 'U_ZERO_ERROR' (0) 125'%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) 126 is in form 'UNORM_FORM_KC'? = no error info: 'U_ZERO_ERROR' (0) 127'%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) 128 is in form 'UNORM_FORM_KC'? = no error info: 'U_ZERO_ERROR' (0) 129'%EF%AC%81' normalized to form 'UNORM_FORM_KC' is 'fi' error info: 'U_ZERO_ERROR' (0) 130 is in form 'UNORM_FORM_KC'? = no error info: 'U_ZERO_ERROR' (0) 131'%E1%BA%9B' normalized to form 'UNORM_FORM_KC' is '%E1%B9%A1' error info: 'U_ZERO_ERROR' (0) 132 is in form 'UNORM_FORM_KC'? = no error info: 'U_ZERO_ERROR' (0) 133'ABC' normalized to form 'UNORM_FORM_KD' is 'ABC' error info: 'U_ZERO_ERROR' (0) 134 is in form 'UNORM_FORM_KD'? = yes error info: 'U_ZERO_ERROR' (0) 135'%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) 136 is in form 'UNORM_FORM_KD'? = no error info: 'U_ZERO_ERROR' (0) 137'%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) 138 is in form 'UNORM_FORM_KD'? = no error info: 'U_ZERO_ERROR' (0) 139'%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) 140 is in form 'UNORM_FORM_KD'? = no error info: 'U_ZERO_ERROR' (0) 141'%EF%AC%81' normalized to form 'UNORM_FORM_KD' is 'fi' error info: 'U_ZERO_ERROR' (0) 142 is in form 'UNORM_FORM_KD'? = no error info: 'U_ZERO_ERROR' (0) 143'%E1%BA%9B' normalized to form 'UNORM_FORM_KD' is 's%CC%87' error info: 'U_ZERO_ERROR' (0) 144 is in form 'UNORM_FORM_KD'? = no error info: 'U_ZERO_ERROR' (0) 145