This source file includes following definitions.
- msgfmt_do_parse
- PHP_FUNCTION
- PHP_FUNCTION
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <unicode/ustring.h>
22
23 #include "php_intl.h"
24 #include "msgformat_class.h"
25 #include "msgformat_parse.h"
26 #include "msgformat_data.h"
27 #include "msgformat_helpers.h"
28 #include "intl_convert.h"
29
30
31 static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t src_len, zval *return_value)
32 {
33 zval *fargs;
34 int count = 0;
35 int i;
36 UChar *usource = NULL;
37 int usrc_len = 0;
38
39 intl_convert_utf8_to_utf16(&usource, &usrc_len, source, src_len, &INTL_DATA_ERROR_CODE(mfo));
40 INTL_METHOD_CHECK_STATUS(mfo, "Converting parse string failed");
41
42 umsg_parse_helper(MSG_FORMAT_OBJECT(mfo), &count, &fargs, usource, usrc_len, &INTL_DATA_ERROR_CODE(mfo));
43 if (usource) {
44 efree(usource);
45 }
46 INTL_METHOD_CHECK_STATUS(mfo, "Parsing failed");
47
48 array_init(return_value);
49 for(i=0;i<count;i++) {
50 add_next_index_zval(return_value, &fargs[i]);
51 }
52 efree(fargs);
53 }
54
55
56
57
58
59
60
61 PHP_FUNCTION( msgfmt_parse )
62 {
63 char *source;
64 size_t source_len;
65 MSG_FORMAT_METHOD_INIT_VARS;
66
67
68
69 if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os",
70 &object, MessageFormatter_ce_ptr, &source, &source_len ) == FAILURE )
71 {
72 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
73 "msgfmt_parse: unable to parse input params", 0 );
74
75 RETURN_FALSE;
76 }
77
78
79 MSG_FORMAT_METHOD_FETCH_OBJECT;
80
81 msgfmt_do_parse(mfo, source, source_len, return_value);
82 }
83
84
85
86
87
88
89
90 PHP_FUNCTION( msgfmt_parse_message )
91 {
92 UChar *spattern = NULL;
93 int spattern_len = 0;
94 char *pattern = NULL;
95 size_t pattern_len = 0;
96 const char *slocale = NULL;
97 size_t slocale_len = 0;
98 char *source = NULL;
99 size_t src_len = 0;
100 MessageFormatter_object mf;
101 MessageFormatter_object *mfo = &mf;
102
103
104 if( zend_parse_parameters( ZEND_NUM_ARGS(), "sss",
105 &slocale, &slocale_len, &pattern, &pattern_len, &source, &src_len ) == FAILURE )
106 {
107 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
108 "msgfmt_parse_message: unable to parse input params", 0 );
109
110 RETURN_FALSE;
111 }
112
113 memset(mfo, 0, sizeof(*mfo));
114 msgformat_data_init(&mfo->mf_data);
115
116 if(pattern && pattern_len) {
117 intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo));
118 if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) )
119 {
120 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
121 "msgfmt_parse_message: error converting pattern to UTF-16", 0 );
122 RETURN_FALSE;
123 }
124 } else {
125 spattern_len = 0;
126 spattern = NULL;
127 }
128
129 if(slocale_len == 0) {
130 slocale = intl_locale_get_default();
131 }
132
133 #ifdef MSG_FORMAT_QUOTE_APOS
134 if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
135 intl_error_set( NULL, U_INVALID_FORMAT_ERROR,
136 "msgfmt_parse_message: error converting pattern to quote-friendly format", 0 );
137 RETURN_FALSE;
138 }
139 #endif
140
141
142 MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, NULL, &INTL_DATA_ERROR_CODE(mfo));
143 if(spattern && spattern_len) {
144 efree(spattern);
145 }
146 INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed");
147
148 msgfmt_do_parse(mfo, source, src_len, return_value);
149
150
151 msgformat_data_free(&mfo->mf_data);
152 }
153
154
155
156
157
158
159
160
161
162