1--TEST-- 2numfmt_get/set_symbol() icu >= 4.8 3--SKIPIF-- 4<?php if( !extension_loaded( 'intl' ) ) print 'skip intl extension not loaded'; ?> 5<?php if (PHP_INT_SIZE != 8) die('skip 64-bit only'); ?> 6--FILE-- 7<?php 8 9/* 10 * Get/set symbol. 11 */ 12 13 14function ut_main() 15{ 16 $longstr = str_repeat("blah", 10); 17 $symbols = array( 18 'DECIMAL_SEPARATOR_SYMBOL' => array( NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, '_._', 12345.123456, NumberFormatter::DECIMAL ), 19 'GROUPING_SEPARATOR_SYMBOL' => array( NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '_,_', 12345.123456, NumberFormatter::DECIMAL ), 20 'PATTERN_SEPARATOR_SYMBOL' => array( NumberFormatter::PATTERN_SEPARATOR_SYMBOL, '_;_', 12345.123456, NumberFormatter::DECIMAL ), 21 'PERCENT_SYMBOL' => array( NumberFormatter::PERCENT_SYMBOL, '_%_', 12345.123456, NumberFormatter::PERCENT ), 22 'ZERO_DIGIT_SYMBOL' => array( NumberFormatter::ZERO_DIGIT_SYMBOL, '_ZD_', 12345.123456, NumberFormatter::DECIMAL ), 23 'DIGIT_SYMBOL' => array( NumberFormatter::DIGIT_SYMBOL, '_DS_', 12345.123456, NumberFormatter::DECIMAL ), 24 'MINUS_SIGN_SYMBOL' => array( NumberFormatter::MINUS_SIGN_SYMBOL, '_-_', -12345.123456, NumberFormatter::DECIMAL ), 25 'PLUS_SIGN_SYMBOL' => array( NumberFormatter::PLUS_SIGN_SYMBOL, '_+_', 12345.123456, NumberFormatter::SCIENTIFIC ), 26 'CURRENCY_SYMBOL' => array( NumberFormatter::CURRENCY_SYMBOL, '_$_', 12345.123456, NumberFormatter::CURRENCY ), 27 'INTL_CURRENCY_SYMBOL' => array( NumberFormatter::INTL_CURRENCY_SYMBOL, '_$_', 12345.123456, NumberFormatter::CURRENCY ), 28 'MONETARY_SEPARATOR_SYMBOL' => array( NumberFormatter::MONETARY_SEPARATOR_SYMBOL, '_MS_', 12345.123456, NumberFormatter::CURRENCY ), 29 'EXPONENTIAL_SYMBOL' => array( NumberFormatter::EXPONENTIAL_SYMBOL, '_E_', 12345.123456, NumberFormatter::SCIENTIFIC ), 30 'PERMILL_SYMBOL' => array( NumberFormatter::PERMILL_SYMBOL, '_PS_', 12345.123456, NumberFormatter::DECIMAL ), 31 'PAD_ESCAPE_SYMBOL' => array( NumberFormatter::PAD_ESCAPE_SYMBOL, '_PE_', 12345.123456, NumberFormatter::DECIMAL ), 32 'INFINITY_SYMBOL' => array( NumberFormatter::INFINITY_SYMBOL, '_IS_', 12345.123456, NumberFormatter::DECIMAL ), 33 'NAN_SYMBOL' => array( NumberFormatter::NAN_SYMBOL, '_N_', 12345.123456, NumberFormatter::DECIMAL ), 34 'SIGNIFICANT_DIGIT_SYMBOL' => array( NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL, '_SD_', 12345.123456, NumberFormatter::DECIMAL ), 35 'MONETARY_GROUPING_SEPARATOR_SYMBOL' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, '_MG_', 12345.123456, NumberFormatter::CURRENCY ), 36 'MONETARY_GROUPING_SEPARATOR_SYMBOL-2' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, " ", 12345.123456, NumberFormatter::CURRENCY ), 37 'MONETARY_GROUPING_SEPARATOR_SYMBOL-3' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $longstr, 12345.123456, NumberFormatter::CURRENCY ), 38 ); 39 40 $res_str = ''; 41 42 foreach( $symbols as $symb_name => $data ) 43 { 44 list( $symb, $new_val, $number, $attr ) = $data; 45 46 $fmt = ut_nfmt_create( 'en_US', $attr); 47 48 $res_str .= "\nSymbol '$symb_name'\n"; 49 50 // Get original symbol value. 51 $orig_val = ut_nfmt_get_symbol( $fmt, $symb ); 52 $res_str .= "Default symbol: [$orig_val]\n"; 53 54 // Set a new symbol value. 55 $res_val = ut_nfmt_set_symbol( $fmt, $symb, $new_val ); 56 if( !$res_val ) 57 $res_str .= "set_symbol() error: " . ut_nfmt_get_error_message( $fmt ) . "\n"; 58 59 // Get the symbol value back. 60 $new_val_check = ut_nfmt_get_symbol( $fmt, $symb ); 61 if( !$new_val_check ) 62 $res_str .= "get_symbol() error: " . ut_nfmt_get_error_message( $fmt ) . "\n"; 63 64 $res_str .= "New symbol: [$new_val_check]\n"; 65 66 // Check if the new value has been set. 67 if( $new_val_check !== $new_val ) 68 $res_str .= "ERROR: New $symb_name symbol value has not been set correctly.\n"; 69 70 // Format the number using the new value. 71 $s = ut_nfmt_format( $fmt, $number ); 72 $res_str .= "A number formatted with the new symbol: $s\n"; 73 74 // Restore attribute's symbol. 75 ut_nfmt_set_symbol( $fmt, $symb, $orig_val ); 76 } 77 $badvals = array(2147483648, -2147483648, -1, 4294901761); 78 foreach($badvals as $badval) { 79 if(ut_nfmt_get_symbol( $fmt, 2147483648 )) { 80 $res_str .= "Bad value $badval should return false!\n"; 81 } 82 } 83 return $res_str; 84} 85 86include_once( 'ut_common.inc' ); 87ut_run(); 88 89?> 90--EXPECTF-- 91Symbol 'DECIMAL_SEPARATOR_SYMBOL' 92Default symbol: [.] 93New symbol: [_._] 94A number formatted with the new symbol: 12,345_._123 95 96Symbol 'GROUPING_SEPARATOR_SYMBOL' 97Default symbol: [,] 98New symbol: [_,_] 99A number formatted with the new symbol: 12_,_345.123 100 101Symbol 'PATTERN_SEPARATOR_SYMBOL' 102Default symbol: [;] 103New symbol: [_;_] 104A number formatted with the new symbol: 12,345.123 105 106Symbol 'PERCENT_SYMBOL' 107Default symbol: [%] 108New symbol: [_%_] 109A number formatted with the new symbol: 1,234,512_%_ 110 111Symbol 'ZERO_DIGIT_SYMBOL' 112Default symbol: [0] 113New symbol: [_ZD_] 114A number formatted with the new symbol: 12,345.123 115 116Symbol 'DIGIT_SYMBOL' 117Default symbol: [#] 118New symbol: [_DS_] 119A number formatted with the new symbol: 12,345.123 120 121Symbol 'MINUS_SIGN_SYMBOL' 122Default symbol: [-] 123New symbol: [_-_] 124A number formatted with the new symbol: _-_12,345.123 125 126Symbol 'PLUS_SIGN_SYMBOL' 127Default symbol: [+] 128New symbol: [_+_] 129A number formatted with the new symbol: 1.2345123456E4 130 131Symbol 'CURRENCY_SYMBOL' 132Default symbol: [$] 133New symbol: [_$_] 134A number formatted with the new symbol: _$_%A12,345.12 135 136Symbol 'INTL_CURRENCY_SYMBOL' 137Default symbol: [USD] 138New symbol: [_$_] 139A number formatted with the new symbol: $12,345.12 140 141Symbol 'MONETARY_SEPARATOR_SYMBOL' 142Default symbol: [.] 143New symbol: [_MS_] 144A number formatted with the new symbol: $12,345_MS_12 145 146Symbol 'EXPONENTIAL_SYMBOL' 147Default symbol: [E] 148New symbol: [_E_] 149A number formatted with the new symbol: 1.2345123456_E_4 150 151Symbol 'PERMILL_SYMBOL' 152Default symbol: [‰] 153New symbol: [_PS_] 154A number formatted with the new symbol: 12,345.123 155 156Symbol 'PAD_ESCAPE_SYMBOL' 157Default symbol: [*] 158New symbol: [_PE_] 159A number formatted with the new symbol: 12,345.123 160 161Symbol 'INFINITY_SYMBOL' 162Default symbol: [∞] 163New symbol: [_IS_] 164A number formatted with the new symbol: 12,345.123 165 166Symbol 'NAN_SYMBOL' 167Default symbol: [NaN] 168New symbol: [_N_] 169A number formatted with the new symbol: 12,345.123 170 171Symbol 'SIGNIFICANT_DIGIT_SYMBOL' 172Default symbol: [@] 173New symbol: [_SD_] 174A number formatted with the new symbol: 12,345.123 175 176Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL' 177Default symbol: [,] 178New symbol: [_MG_] 179A number formatted with the new symbol: $12_MG_345.12 180 181Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL-2' 182Default symbol: [,] 183New symbol: [ ] 184A number formatted with the new symbol: $12 345.12 185 186Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL-3' 187Default symbol: [,] 188New symbol: [blahblahblahblahblahblahblahblahblahblah] 189A number formatted with the new symbol: $12blahblahblahblahblahblahblahblahblahblah345.12 190