@@ -2177,14 +2177,14 @@ static PHP_FUNCTION(preg_split)
2177
2177
}
2178
2178
2179
2179
pce -> refcount ++ ;
2180
- php_pcre_split_impl (pce , ZSTR_VAL ( subject ), ( int ) ZSTR_LEN ( subject ) , return_value , (int )limit_val , flags );
2180
+ php_pcre_split_impl (pce , subject , return_value , (int )limit_val , flags );
2181
2181
pce -> refcount -- ;
2182
2182
}
2183
2183
/* }}} */
2184
2184
2185
2185
/* {{{ php_pcre_split
2186
2186
*/
2187
- PHPAPI void php_pcre_split_impl (pcre_cache_entry * pce , char * subject , int subject_len , zval * return_value ,
2187
+ PHPAPI void php_pcre_split_impl (pcre_cache_entry * pce , zend_string * subject_str , zval * return_value ,
2188
2188
zend_long limit_val , zend_long flags )
2189
2189
{
2190
2190
pcre_extra * extra = pce -> extra ;/* Holds results of studying */
@@ -2235,7 +2235,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
2235
2235
/* Start at the beginning of the string */
2236
2236
start_offset = 0 ;
2237
2237
next_offset = 0 ;
2238
- last_match = subject ;
2238
+ last_match = ZSTR_VAL ( subject_str ) ;
2239
2239
PCRE_G (error_code ) = PHP_PCRE_NO_ERROR ;
2240
2240
2241
2241
#ifdef HAVE_PCRE_JIT_SUPPORT
@@ -2249,13 +2249,13 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
2249
2249
#ifdef HAVE_PCRE_JIT_SUPPORT
2250
2250
if ((extra -> flags & PCRE_EXTRA_EXECUTABLE_JIT )
2251
2251
&& no_utf_check && !g_notempty ) {
2252
- count = pcre_jit_exec (pce -> re , extra , subject ,
2253
- subject_len , start_offset ,
2252
+ count = pcre_jit_exec (pce -> re , extra , ZSTR_VAL ( subject_str ) ,
2253
+ ZSTR_LEN ( subject_str ) , start_offset ,
2254
2254
no_utf_check |g_notempty , offsets , size_offsets , jit_stack );
2255
2255
} else
2256
2256
#endif
2257
- count = pcre_exec (pce -> re , extra , subject ,
2258
- subject_len , start_offset ,
2257
+ count = pcre_exec (pce -> re , extra , ZSTR_VAL ( subject_str ) ,
2258
+ ZSTR_LEN ( subject_str ) , start_offset ,
2259
2259
no_utf_check |g_notempty , offsets , size_offsets );
2260
2260
2261
2261
/* the string was already proved to be valid UTF-8 */
@@ -2269,14 +2269,14 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
2269
2269
2270
2270
/* If something matched */
2271
2271
if (count > 0 && (offsets [1 ] - offsets [0 ] >= 0 )) {
2272
- if (!no_empty || & subject [offsets [0 ]] != last_match ) {
2272
+ if (!no_empty || & ZSTR_VAL ( subject_str ) [offsets [0 ]] != last_match ) {
2273
2273
2274
2274
if (offset_capture ) {
2275
2275
/* Add (match, offset) pair to the return value */
2276
- add_offset_pair (return_value , last_match , (int )(& subject [offsets [0 ]]- last_match ), next_offset , NULL , 0 );
2276
+ add_offset_pair (return_value , last_match , (int )(& ZSTR_VAL ( subject_str ) [offsets [0 ]]- last_match ), next_offset , NULL , 0 );
2277
2277
} else {
2278
2278
/* Add the piece to the return value */
2279
- ZVAL_STRINGL (& tmp , last_match , & subject [offsets [0 ]]- last_match );
2279
+ ZVAL_STRINGL (& tmp , last_match , & ZSTR_VAL ( subject_str ) [offsets [0 ]]- last_match );
2280
2280
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & tmp );
2281
2281
}
2282
2282
@@ -2285,7 +2285,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
2285
2285
limit_val -- ;
2286
2286
}
2287
2287
2288
- last_match = & subject [offsets [1 ]];
2288
+ last_match = & ZSTR_VAL ( subject_str ) [offsets [1 ]];
2289
2289
next_offset = offsets [1 ];
2290
2290
2291
2291
if (delim_capture ) {
@@ -2295,9 +2295,9 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
2295
2295
/* If we have matched a delimiter */
2296
2296
if (!no_empty || match_len > 0 ) {
2297
2297
if (offset_capture ) {
2298
- add_offset_pair (return_value , & subject [offsets [i <<1 ]], match_len , offsets [i <<1 ], NULL , 0 );
2298
+ add_offset_pair (return_value , & ZSTR_VAL ( subject_str ) [offsets [i <<1 ]], match_len , offsets [i <<1 ], NULL , 0 );
2299
2299
} else {
2300
- ZVAL_STRINGL (& tmp , & subject [offsets [i <<1 ]], match_len );
2300
+ ZVAL_STRINGL (& tmp , & ZSTR_VAL ( subject_str ) [offsets [i <<1 ]], match_len );
2301
2301
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & tmp );
2302
2302
}
2303
2303
}
@@ -2318,8 +2318,8 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
2318
2318
this is not necessarily the end. We need to advance
2319
2319
the start offset, and continue. Fudge the offset values
2320
2320
to achieve this, unless we're already at the end of the string. */
2321
- if (g_notempty != 0 && start_offset < subject_len ) {
2322
- start_offset += calculate_unit_length (pce , subject + start_offset );
2321
+ if (g_notempty != 0 && start_offset < ZSTR_LEN ( subject_str ) ) {
2322
+ start_offset += calculate_unit_length (pce , ZSTR_VAL ( subject_str ) + start_offset );
2323
2323
g_notempty = 0 ;
2324
2324
} else {
2325
2325
break ;
@@ -2331,15 +2331,19 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
2331
2331
}
2332
2332
2333
2333
2334
- start_offset = (int )(last_match - subject ); /* the offset might have been incremented, but without further successful matches */
2334
+ start_offset = (int )(last_match - ZSTR_VAL ( subject_str ) ); /* the offset might have been incremented, but without further successful matches */
2335
2335
2336
- if (!no_empty || start_offset < subject_len ) {
2336
+ if (!no_empty || start_offset < ZSTR_LEN ( subject_str ) ) {
2337
2337
if (offset_capture ) {
2338
2338
/* Add the last (match, offset) pair to the return value */
2339
- add_offset_pair (return_value , & subject [start_offset ], subject_len - start_offset , start_offset , NULL , 0 );
2339
+ add_offset_pair (return_value , & ZSTR_VAL ( subject_str ) [start_offset ], ZSTR_LEN ( subject_str ) - start_offset , start_offset , NULL , 0 );
2340
2340
} else {
2341
2341
/* Add the last piece to the return value */
2342
- ZVAL_STRINGL (& tmp , last_match , subject + subject_len - last_match );
2342
+ if (last_match == ZSTR_VAL (subject_str )) {
2343
+ ZVAL_STR_COPY (& tmp , subject_str );
2344
+ } else {
2345
+ ZVAL_STRINGL (& tmp , last_match , ZSTR_VAL (subject_str ) + ZSTR_LEN (subject_str ) - last_match );
2346
+ }
2343
2347
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & tmp );
2344
2348
}
2345
2349
}
0 commit comments