1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
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 /* {{{ formatter_register_constants
30 * Register constants common for the both (OO and procedural)
31 * APIs.
32 */
formatter_register_constants(INIT_FUNC_ARGS)33 void formatter_register_constants( INIT_FUNC_ARGS )
34 {
35 if( NumberFormatter_ce_ptr == NULL) {
36 zend_error(E_ERROR, "NumberFormatter class not defined");
37 }
38
39 #define FORMATTER_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_PERSISTENT | CONST_CS)
40 #define FORMATTER_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( NumberFormatter_ce_ptr, ZEND_STRS( #x ) - 1, UNUM_##x );
41 #define FORMATTER_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( NumberFormatter_ce_ptr, ZEND_STRS( name ) - 1, value );
42
43 /* UNumberFormatStyle constants */
44 FORMATTER_EXPOSE_CLASS_CONST( PATTERN_DECIMAL );
45 FORMATTER_EXPOSE_CLASS_CONST( DECIMAL );
46 FORMATTER_EXPOSE_CLASS_CONST( CURRENCY );
47 FORMATTER_EXPOSE_CLASS_CONST( PERCENT );
48 FORMATTER_EXPOSE_CLASS_CONST( SCIENTIFIC );
49 FORMATTER_EXPOSE_CLASS_CONST( SPELLOUT );
50 FORMATTER_EXPOSE_CLASS_CONST( ORDINAL );
51 FORMATTER_EXPOSE_CLASS_CONST( DURATION );
52 FORMATTER_EXPOSE_CLASS_CONST( PATTERN_RULEBASED );
53 FORMATTER_EXPOSE_CLASS_CONST( IGNORE );
54 #if U_ICU_VERSION_MAJOR_NUM >= 53
55 FORMATTER_EXPOSE_CLASS_CONST( CURRENCY_ACCOUNTING );
56 #endif
57 FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "DEFAULT_STYLE", UNUM_DEFAULT );
58
59 /* UNumberFormatRoundingMode */
60 FORMATTER_EXPOSE_CLASS_CONST( ROUND_CEILING );
61 FORMATTER_EXPOSE_CLASS_CONST( ROUND_FLOOR );
62 FORMATTER_EXPOSE_CLASS_CONST( ROUND_DOWN );
63 FORMATTER_EXPOSE_CLASS_CONST( ROUND_UP );
64 FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFEVEN );
65 FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFDOWN );
66 FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFUP );
67
68 /* UNumberFormatPadPosition */
69 FORMATTER_EXPOSE_CLASS_CONST( PAD_BEFORE_PREFIX );
70 FORMATTER_EXPOSE_CLASS_CONST( PAD_AFTER_PREFIX );
71 FORMATTER_EXPOSE_CLASS_CONST( PAD_BEFORE_SUFFIX );
72 FORMATTER_EXPOSE_CLASS_CONST( PAD_AFTER_SUFFIX );
73
74 /* UNumberFormatAttribute */
75 FORMATTER_EXPOSE_CLASS_CONST( PARSE_INT_ONLY );
76 FORMATTER_EXPOSE_CLASS_CONST( GROUPING_USED );
77 FORMATTER_EXPOSE_CLASS_CONST( DECIMAL_ALWAYS_SHOWN );
78 FORMATTER_EXPOSE_CLASS_CONST( MAX_INTEGER_DIGITS );
79 FORMATTER_EXPOSE_CLASS_CONST( MIN_INTEGER_DIGITS );
80 FORMATTER_EXPOSE_CLASS_CONST( INTEGER_DIGITS );
81 FORMATTER_EXPOSE_CLASS_CONST( MAX_FRACTION_DIGITS );
82 FORMATTER_EXPOSE_CLASS_CONST( MIN_FRACTION_DIGITS );
83 FORMATTER_EXPOSE_CLASS_CONST( FRACTION_DIGITS );
84 FORMATTER_EXPOSE_CLASS_CONST( MULTIPLIER );
85 FORMATTER_EXPOSE_CLASS_CONST( GROUPING_SIZE );
86 FORMATTER_EXPOSE_CLASS_CONST( ROUNDING_MODE );
87 FORMATTER_EXPOSE_CLASS_CONST( ROUNDING_INCREMENT );
88 FORMATTER_EXPOSE_CLASS_CONST( FORMAT_WIDTH );
89 FORMATTER_EXPOSE_CLASS_CONST( PADDING_POSITION );
90 FORMATTER_EXPOSE_CLASS_CONST( SECONDARY_GROUPING_SIZE );
91 FORMATTER_EXPOSE_CLASS_CONST( SIGNIFICANT_DIGITS_USED );
92 FORMATTER_EXPOSE_CLASS_CONST( MIN_SIGNIFICANT_DIGITS );
93 FORMATTER_EXPOSE_CLASS_CONST( MAX_SIGNIFICANT_DIGITS );
94 FORMATTER_EXPOSE_CLASS_CONST( LENIENT_PARSE );
95
96 /* UNumberFormatTextAttribute */
97 FORMATTER_EXPOSE_CLASS_CONST( POSITIVE_PREFIX );
98 FORMATTER_EXPOSE_CLASS_CONST( POSITIVE_SUFFIX );
99 FORMATTER_EXPOSE_CLASS_CONST( NEGATIVE_PREFIX );
100 FORMATTER_EXPOSE_CLASS_CONST( NEGATIVE_SUFFIX );
101 FORMATTER_EXPOSE_CLASS_CONST( PADDING_CHARACTER );
102 FORMATTER_EXPOSE_CLASS_CONST( CURRENCY_CODE );
103 FORMATTER_EXPOSE_CLASS_CONST( DEFAULT_RULESET );
104 FORMATTER_EXPOSE_CLASS_CONST( PUBLIC_RULESETS );
105
106 /* UNumberFormatSymbol */
107 FORMATTER_EXPOSE_CLASS_CONST( DECIMAL_SEPARATOR_SYMBOL );
108 FORMATTER_EXPOSE_CLASS_CONST( GROUPING_SEPARATOR_SYMBOL );
109 FORMATTER_EXPOSE_CLASS_CONST( PATTERN_SEPARATOR_SYMBOL );
110 FORMATTER_EXPOSE_CLASS_CONST( PERCENT_SYMBOL );
111 FORMATTER_EXPOSE_CLASS_CONST( ZERO_DIGIT_SYMBOL );
112 FORMATTER_EXPOSE_CLASS_CONST( DIGIT_SYMBOL );
113 FORMATTER_EXPOSE_CLASS_CONST( MINUS_SIGN_SYMBOL );
114 FORMATTER_EXPOSE_CLASS_CONST( PLUS_SIGN_SYMBOL );
115 FORMATTER_EXPOSE_CLASS_CONST( CURRENCY_SYMBOL );
116 FORMATTER_EXPOSE_CLASS_CONST( INTL_CURRENCY_SYMBOL );
117 FORMATTER_EXPOSE_CLASS_CONST( MONETARY_SEPARATOR_SYMBOL );
118 FORMATTER_EXPOSE_CLASS_CONST( EXPONENTIAL_SYMBOL );
119 FORMATTER_EXPOSE_CLASS_CONST( PERMILL_SYMBOL );
120 FORMATTER_EXPOSE_CLASS_CONST( PAD_ESCAPE_SYMBOL );
121 FORMATTER_EXPOSE_CLASS_CONST( INFINITY_SYMBOL );
122 FORMATTER_EXPOSE_CLASS_CONST( NAN_SYMBOL );
123 FORMATTER_EXPOSE_CLASS_CONST( SIGNIFICANT_DIGIT_SYMBOL );
124 FORMATTER_EXPOSE_CLASS_CONST( MONETARY_GROUPING_SEPARATOR_SYMBOL );
125
126 FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_DEFAULT", FORMAT_TYPE_DEFAULT );
127 FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_INT32", FORMAT_TYPE_INT32 );
128 FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_INT64", FORMAT_TYPE_INT64 );
129 FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_DOUBLE", FORMAT_TYPE_DOUBLE );
130 FORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "TYPE_CURRENCY", FORMAT_TYPE_CURRENCY );
131
132 #undef FORMATTER_EXPOSE_CUSTOM_CLASS_CONST
133 #undef FORMATTER_EXPOSE_CLASS_CONST
134 #undef FORMATTER_EXPOSE_CONST
135 }
136 /* }}} */
137