1--TEST-- 2numfmt_get/set_text_attribute() ICU >= 56.1 3--EXTENSIONS-- 4intl 5--SKIPIF-- 6<?php if (version_compare(INTL_ICU_VERSION, '56.1') < 0) die('skip for ICU >= 56.1'); ?> 7--FILE-- 8<?php 9 10/* 11 * Get/set text attribute. 12 */ 13 14 15function ut_main() 16{ 17 // Array with data for testing 18 $long_str = str_repeat('blah', 100); 19 $attributes = array( 20 'POSITIVE_PREFIX' => array( NumberFormatter::POSITIVE_PREFIX, '_+_', 12345.1234 ), 21 'POSITIVE_SUFFIX' => array( NumberFormatter::POSITIVE_SUFFIX, '_+_', 12345.1234 ), 22 'NEGATIVE_PREFIX' => array( NumberFormatter::NEGATIVE_PREFIX, '_-_', -12345.1234 ), 23 'NEGATIVE_SUFFIX' => array( NumberFormatter::NEGATIVE_SUFFIX, '_-_', -12345.1234 ), 24 'PADDING_CHARACTER' => array( NumberFormatter::PADDING_CHARACTER, '^', 12345.1234 ), 25 'POSITIVE_PREFIX-2' => array( NumberFormatter::POSITIVE_PREFIX, $long_str, 12345.1234 ), 26// 'CURRENCY_CODE' => array( NumberFormatter::CURRENCY_CODE, '_C_', 12345.1234 ) 27// 'DEFAULT_RULESET' => array( NumberFormatter::DEFAULT_RULESET, '_DR_', 12345.1234 ), 28// 'PUBLIC_RULESETS' => array( NumberFormatter::PUBLIC_RULESETS, '_PR_', 12345.1234 ) 29 ); 30 31 $res_str = ''; 32 33 $fmt = ut_nfmt_create( "en_US", NumberFormatter::DECIMAL ); 34 35 foreach( $attributes as $attr_name => $data ) 36 { 37 list( $attr, $new_val, $test_number ) = $data; 38 $res_str .= "\nAttribute $attr_name\n"; 39 40 if( $attr == NumberFormatter::PADDING_CHARACTER ) 41 ut_nfmt_set_attribute( $fmt, NumberFormatter::FORMAT_WIDTH, 21 ); 42 43 // Get default attribute's value 44 $def_val = ut_nfmt_get_text_attribute( $fmt, $attr ); 45 if( $def_val === false ) 46 $res_str .= "get_text_attribute() error: " . ut_nfmt_get_error_message( $fmt ) . "\n"; 47 48 $res_str .= "Default value: [$def_val]\n"; 49 $res_str .= "Formatting number with default value: " . ut_nfmt_format( $fmt, $test_number ) . "\n"; 50 51 // Set new attribute's value and see if it works out. 52 $res_val = ut_nfmt_set_text_attribute( $fmt, $attr, $new_val ); 53 if( !$res_val ) 54 $res_str .= "set_text_attribute() error: " . ut_nfmt_get_error_message( $fmt ) . "\n"; 55 56 // Get attribute value back. 57 $new_val_check = ut_nfmt_get_text_attribute( $fmt, $attr ); 58 $res_str .= "New value: [$new_val_check]\n"; 59 $res_str .= "Formatting number with new value: " . ut_nfmt_format( $fmt, $test_number ) . "\n"; 60 61 // Check if the new value has been set. 62 if( $new_val !== $new_val_check ) 63 $res_str .= "ERROR: New $attr_name symbol value has not been set correctly.\n"; 64 65 // Restore attribute's value to default 66 ut_nfmt_set_text_attribute( $fmt, $attr, $def_val ); 67 68 if( $attr == NumberFormatter::PADDING_CHARACTER ) 69 ut_nfmt_set_attribute( $fmt, NumberFormatter::FORMAT_WIDTH, 0 ); 70 } 71 72 // 73 $fmt = ut_nfmt_create( "uk_UA", NumberFormatter::CURRENCY ); 74 $res_str .= sprintf( "\nCurrency ISO-code for locale 'uk_UA' is: %s\n", 75 ut_nfmt_get_text_attribute( $fmt, NumberFormatter::CURRENCY_CODE ) ); 76 77 return $res_str; 78} 79 80include_once( 'ut_common.inc' ); 81ut_run(); 82 83?> 84--EXPECT-- 85Attribute POSITIVE_PREFIX 86Default value: [] 87Formatting number with default value: 12,345.123 88New value: [_+_] 89Formatting number with new value: _+_12,345.123 90 91Attribute POSITIVE_SUFFIX 92Default value: [] 93Formatting number with default value: 12,345.123 94New value: [_+_] 95Formatting number with new value: 12,345.123_+_ 96 97Attribute NEGATIVE_PREFIX 98Default value: [-] 99Formatting number with default value: -12,345.123 100New value: [_-_] 101Formatting number with new value: _-_12,345.123 102 103Attribute NEGATIVE_SUFFIX 104Default value: [] 105Formatting number with default value: -12,345.123 106New value: [_-_] 107Formatting number with new value: -12,345.123_-_ 108 109Attribute PADDING_CHARACTER 110Default value: [ ] 111Formatting number with default value: 12,345.123 112New value: [^] 113Formatting number with new value: ^^^^^^^^^^^12,345.123 114 115Attribute POSITIVE_PREFIX-2 116Default value: [] 117Formatting number with default value: 12,345.123 118New value: [blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah] 119Formatting number with new value: blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah12,345.123 120 121Currency ISO-code for locale 'uk_UA' is: UAH 122