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