@@ -169,6 +169,73 @@ php_mbregex_compile_pattern(mb_regex_t *pre, const char *pattern, int patlen, in
169
169
return res ;
170
170
}
171
171
172
+ static size_t
173
+ _php_mb_regex_get_option_string (char * str , size_t len , int option )
174
+ {
175
+ size_t len_left = len ;
176
+ size_t len_req = 0 ;
177
+ char * p = str ;
178
+
179
+
180
+ if ((option & MBRE_OPTION_IGNORECASE ) != 0 ) {
181
+ if (len_left > 0 ) {
182
+ -- len_left ;
183
+ * (p ++ ) = 'i' ;
184
+ }
185
+ ++ len_req ;
186
+ }
187
+
188
+ if ((option & MBRE_OPTION_EXTENDED ) != 0 ) {
189
+ if (len_left > 0 ) {
190
+ -- len_left ;
191
+ * (p ++ ) = 'x' ;
192
+ }
193
+ ++ len_req ;
194
+ }
195
+
196
+ if ((option & MBRE_OPTION_POSIXLINE ) == MBRE_OPTION_POSIXLINE ) {
197
+ if (len_left > 0 ) {
198
+ -- len_left ;
199
+ * (p ++ ) = 'p' ;
200
+ }
201
+ ++ len_req ;
202
+ } else {
203
+ if ((option & MBRE_OPTION_MULTILINE ) != 0 ) {
204
+ if (len_left > 0 ) {
205
+ -- len_left ;
206
+ * (p ++ ) = 'm' ;
207
+ }
208
+ ++ len_req ;
209
+ }
210
+
211
+ if ((option & MBRE_OPTION_SINGLELINE ) != 0 ) {
212
+ if (len_left > 0 ) {
213
+ -- len_left ;
214
+ * (p ++ ) = 's' ;
215
+ }
216
+ ++ len_req ;
217
+ }
218
+ }
219
+ if ((option & MBRE_OPTION_LONGEST ) != 0 ) {
220
+ if (len_left > 0 ) {
221
+ -- len_left ;
222
+ * (p ++ ) = 'l' ;
223
+ }
224
+ ++ len_req ;
225
+ }
226
+ if (len_left > 0 ) {
227
+ -- len_left ;
228
+ * (p ++ ) = '\0' ;
229
+ }
230
+
231
+ ++ len_req ;
232
+ if (len < len_req ) {
233
+ return len_req ;
234
+ }
235
+
236
+ return 0 ;
237
+ }
238
+
172
239
static void
173
240
_php_mb_regex_init_options (const char * parg , int narg , int * option , int * eval )
174
241
{
@@ -974,18 +1041,28 @@ PHPAPI int php_mb_regex_set_options_by_string( const char *opt_str, int len TSRM
974
1041
}
975
1042
/* }}} */
976
1043
977
- /* {{{ proto bool mb_regex_set_options([string options])
978
- Set the default options for mbregex functions */
1044
+ /* {{{ proto string mb_regex_set_options([string options])
1045
+ Set or get the default options for mbregex functions */
979
1046
PHP_FUNCTION (mb_regex_set_options )
980
1047
{
981
- char * string ;
1048
+ int opt ;
1049
+ char * string = NULL ;
982
1050
int string_len ;
983
- if ( zend_parse_parameters ( ZEND_NUM_ARGS () TSRMLS_CC , "s" ,
1051
+ char buf [16 ];
1052
+
1053
+ if ( zend_parse_parameters ( ZEND_NUM_ARGS () TSRMLS_CC , "|s" ,
984
1054
& string , & string_len ) == FAILURE ) {
985
1055
RETURN_FALSE ;
986
1056
}
987
- php_mb_regex_set_options_by_string ( (const char * )string , string_len TSRMLS_CC );
988
- RETURN_TRUE ;
1057
+ if (string != NULL ) {
1058
+ opt = php_mb_regex_set_options_by_string ( (const char * )string ,
1059
+ string_len TSRMLS_CC );
1060
+ } else {
1061
+ opt = MBSTRG (regex_default_options );
1062
+ }
1063
+ _php_mb_regex_get_option_string (buf , sizeof (buf ), opt );
1064
+
1065
+ RETVAL_STRING (buf , 1 );
989
1066
}
990
1067
/* }}} */
991
1068
0 commit comments