xref: /PHP-5.4/ext/intl/formatter/formatter.c (revision 9762609c)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5                                                        |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | http://www.php.net/license/3_01.txt                                  |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Stanislav Malyshev <stas@zend.com>                          |
14    +----------------------------------------------------------------------+
15  */
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <unicode/utypes.h>
22 #include <unicode/unum.h>
23 #include <unicode/ustring.h>
24 
25 #include "php_intl.h"
26 #include "formatter_class.h"
27 #include "formatter_format.h"
28 
29 #if U_ICU_VERSION_MAJOR_NUM == 3 && U_ICU_VERSION_MINOR_NUM <= 4
30 #define UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL 17
31 #endif
32 
33 /* {{{ formatter_register_constants
34  * Register constants common for the both (OO and procedural)
35  * APIs.
36  */
formatter_register_constants(INIT_FUNC_ARGS)37 void formatter_register_constants( INIT_FUNC_ARGS )
38 {
39 	if( NumberFormatter_ce_ptr == NULL) {
40 		zend_error(E_ERROR, "NumberFormatter class not defined");
41 	}
42 
43 	#define FORMATTER_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS)
44 	#define FORMATTER_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( NumberFormatter_ce_ptr, ZEND_STRS( #x ) - 1, UNUM_##x TSRMLS_CC );
45 	#define FORMATTER_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( NumberFormatter_ce_ptr, ZEND_STRS( name ) - 1, value TSRMLS_CC );
46 
47 	/* UNumberFormatStyle constants */
48 	FORMATTER_EXPOSE_CLASS_CONST( PATTERN_DECIMAL );
49 	FORMATTER_EXPOSE_CLASS_CONST( DECIMAL );
50 	FORMATTER_EXPOSE_CLASS_CONST( CURRENCY );
51 	FORMATTER_EXPOSE_CLASS_CONST( PERCENT );
52 	FORMATTER_EXPOSE_CLASS_CONST( SCIENTIFIC );
53 	FORMATTER_EXPOSE_CLASS_CONST( SPELLOUT );
54 	FORMATTER_EXPOSE_CLASS_CONST( ORDINAL );
55 	FORMATTER_EXPOSE_CLASS_CONST( DURATION );
56 	FORMATTER_EXPOSE_CLASS_CONST( PATTERN_RULEBASED );
57 	FORMATTER_EXPOSE_CLASS_CONST( IGNORE );
58 
59 	FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "DEFAULT_STYLE",  UNUM_DEFAULT );
60 
61 /* workaround for ICU bug */
62 #if U_ICU_VERSION_MAJOR_NUM == 3 && U_ICU_VERSION_MINOR_NUM < 8
63 #define UNUM_ROUND_HALFEVEN UNUM_FOUND_HALFEVEN
64 #endif
65 
66 	/* UNumberFormatRoundingMode */
67 	FORMATTER_EXPOSE_CLASS_CONST( ROUND_CEILING );
68 	FORMATTER_EXPOSE_CLASS_CONST( ROUND_FLOOR );
69 	FORMATTER_EXPOSE_CLASS_CONST( ROUND_DOWN );
70 	FORMATTER_EXPOSE_CLASS_CONST( ROUND_UP );
71 	FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFEVEN );
72 	FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFDOWN );
73 	FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFUP );
74 
75 	/* UNumberFormatPadPosition */
76 	FORMATTER_EXPOSE_CLASS_CONST( PAD_BEFORE_PREFIX );
77 	FORMATTER_EXPOSE_CLASS_CONST( PAD_AFTER_PREFIX );
78 	FORMATTER_EXPOSE_CLASS_CONST( PAD_BEFORE_SUFFIX );
79 	FORMATTER_EXPOSE_CLASS_CONST( PAD_AFTER_SUFFIX );
80 
81 	/* UNumberFormatAttribute */
82 	FORMATTER_EXPOSE_CLASS_CONST( PARSE_INT_ONLY );
83 	FORMATTER_EXPOSE_CLASS_CONST( GROUPING_USED );
84 	FORMATTER_EXPOSE_CLASS_CONST( DECIMAL_ALWAYS_SHOWN );
85 	FORMATTER_EXPOSE_CLASS_CONST( MAX_INTEGER_DIGITS );
86 	FORMATTER_EXPOSE_CLASS_CONST( MIN_INTEGER_DIGITS );
87 	FORMATTER_EXPOSE_CLASS_CONST( INTEGER_DIGITS );
88 	FORMATTER_EXPOSE_CLASS_CONST( MAX_FRACTION_DIGITS );
89 	FORMATTER_EXPOSE_CLASS_CONST( MIN_FRACTION_DIGITS );
90 	FORMATTER_EXPOSE_CLASS_CONST( FRACTION_DIGITS );
91 	FORMATTER_EXPOSE_CLASS_CONST( MULTIPLIER );
92 	FORMATTER_EXPOSE_CLASS_CONST( GROUPING_SIZE );
93 	FORMATTER_EXPOSE_CLASS_CONST( ROUNDING_MODE );
94 	FORMATTER_EXPOSE_CLASS_CONST( ROUNDING_INCREMENT );
95 	FORMATTER_EXPOSE_CLASS_CONST( FORMAT_WIDTH );
96 	FORMATTER_EXPOSE_CLASS_CONST( PADDING_POSITION );
97 	FORMATTER_EXPOSE_CLASS_CONST( SECONDARY_GROUPING_SIZE );
98 	FORMATTER_EXPOSE_CLASS_CONST( SIGNIFICANT_DIGITS_USED );
99 	FORMATTER_EXPOSE_CLASS_CONST( MIN_SIGNIFICANT_DIGITS );
100 	FORMATTER_EXPOSE_CLASS_CONST( MAX_SIGNIFICANT_DIGITS );
101 	FORMATTER_EXPOSE_CLASS_CONST( LENIENT_PARSE );
102 
103 	/* UNumberFormatTextAttribute */
104 	FORMATTER_EXPOSE_CLASS_CONST( POSITIVE_PREFIX );
105 	FORMATTER_EXPOSE_CLASS_CONST( POSITIVE_SUFFIX );
106 	FORMATTER_EXPOSE_CLASS_CONST( NEGATIVE_PREFIX );
107 	FORMATTER_EXPOSE_CLASS_CONST( NEGATIVE_SUFFIX );
108 	FORMATTER_EXPOSE_CLASS_CONST( PADDING_CHARACTER );
109 	FORMATTER_EXPOSE_CLASS_CONST( CURRENCY_CODE );
110 	FORMATTER_EXPOSE_CLASS_CONST( DEFAULT_RULESET );
111 	FORMATTER_EXPOSE_CLASS_CONST( PUBLIC_RULESETS );
112 
113 	/* UNumberFormatSymbol */
114 	FORMATTER_EXPOSE_CLASS_CONST( DECIMAL_SEPARATOR_SYMBOL );
115 	FORMATTER_EXPOSE_CLASS_CONST( GROUPING_SEPARATOR_SYMBOL );
116 	FORMATTER_EXPOSE_CLASS_CONST( PATTERN_SEPARATOR_SYMBOL );
117 	FORMATTER_EXPOSE_CLASS_CONST( PERCENT_SYMBOL );
118 	FORMATTER_EXPOSE_CLASS_CONST( ZERO_DIGIT_SYMBOL );
119 	FORMATTER_EXPOSE_CLASS_CONST( DIGIT_SYMBOL );
120 	FORMATTER_EXPOSE_CLASS_CONST( MINUS_SIGN_SYMBOL );
121 	FORMATTER_EXPOSE_CLASS_CONST( PLUS_SIGN_SYMBOL );
122 	FORMATTER_EXPOSE_CLASS_CONST( CURRENCY_SYMBOL );
123 	FORMATTER_EXPOSE_CLASS_CONST( INTL_CURRENCY_SYMBOL );
124 	FORMATTER_EXPOSE_CLASS_CONST( MONETARY_SEPARATOR_SYMBOL );
125 	FORMATTER_EXPOSE_CLASS_CONST( EXPONENTIAL_SYMBOL );
126 	FORMATTER_EXPOSE_CLASS_CONST( PERMILL_SYMBOL );
127 	FORMATTER_EXPOSE_CLASS_CONST( PAD_ESCAPE_SYMBOL );
128 	FORMATTER_EXPOSE_CLASS_CONST( INFINITY_SYMBOL );
129 	FORMATTER_EXPOSE_CLASS_CONST( NAN_SYMBOL );
130 	FORMATTER_EXPOSE_CLASS_CONST( SIGNIFICANT_DIGIT_SYMBOL );
131 	FORMATTER_EXPOSE_CLASS_CONST( MONETARY_GROUPING_SEPARATOR_SYMBOL );
132 
133 	FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_DEFAULT", FORMAT_TYPE_DEFAULT );
134 	FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_INT32", FORMAT_TYPE_INT32 );
135 	FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_INT64", FORMAT_TYPE_INT64 );
136 	FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_DOUBLE", FORMAT_TYPE_DOUBLE );
137 	FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_CURRENCY", FORMAT_TYPE_CURRENCY );
138 
139 	#undef FORMATTER_EXPOSE_CUSTOM_CLASS_CONST
140 	#undef FORMATTER_EXPOSE_CLASS_CONST
141 	#undef FORMATTER_EXPOSE_CONST
142 }
143 /* }}} */
144 
145 /*
146  * Local variables:
147  * tab-width: 4
148  * c-basic-offset: 4
149  * End:
150  * vim600: noet sw=4 ts=4 fdm=marker
151  * vim<600: noet sw=4 ts=4
152  */
153