@@ -2493,7 +2493,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
2493
2493
uint32_t options ; /* Execution options */
2494
2494
int count ; /* Count of matched subpatterns */
2495
2495
PCRE2_SIZE start_offset ; /* Where the new search starts */
2496
- char * last_match ; /* Location of last match */
2496
+ PCRE2_SIZE last_match_offset ; /* Location of last match */
2497
2497
uint32_t no_empty ; /* If NO_EMPTY flag is set */
2498
2498
uint32_t delim_capture ; /* If delimiters should be captured */
2499
2499
uint32_t offset_capture ; /* If offsets should be captured */
@@ -2514,10 +2514,9 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
2514
2514
2515
2515
/* Start at the beginning of the string */
2516
2516
start_offset = 0 ;
2517
- last_match = subject ;
2517
+ last_match_offset = 0 ;
2518
2518
PCRE_G (error_code ) = PHP_PCRE_NO_ERROR ;
2519
2519
2520
-
2521
2520
if (limit_val == -1 ) {
2522
2521
/* pass */
2523
2522
} else if (limit_val == 0 ) {
@@ -2565,15 +2564,15 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
2565
2564
break ;
2566
2565
}
2567
2566
2568
- if (!no_empty || & subject [ offsets [0 ]] != last_match ) {
2567
+ if (!no_empty || offsets [0 ] != last_match_offset ) {
2569
2568
if (offset_capture ) {
2570
2569
/* Add (match, offset) pair to the return value */
2571
2570
add_offset_pair (
2572
- return_value , subject , last_match - subject , offsets [0 ],
2571
+ return_value , subject , last_match_offset , offsets [0 ],
2573
2572
NULL , 0 );
2574
2573
} else {
2575
2574
/* Add the piece to the return value */
2576
- ZVAL_STRINGL (& tmp , last_match , & subject [ offsets [0 ]] - last_match );
2575
+ populate_match_value_str (& tmp , subject , last_match_offset , offsets [0 ]);
2577
2576
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & tmp );
2578
2577
}
2579
2578
@@ -2582,27 +2581,24 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
2582
2581
limit_val -- ;
2583
2582
}
2584
2583
2585
- last_match = & subject [offsets [1 ]];
2586
-
2587
2584
if (delim_capture ) {
2588
- size_t i , match_len ;
2585
+ size_t i ;
2589
2586
for (i = 1 ; i < count ; i ++ ) {
2590
- match_len = offsets [2 * i + 1 ] - offsets [2 * i ];
2591
2587
/* If we have matched a delimiter */
2592
- if (!no_empty || match_len > 0 ) {
2588
+ if (!no_empty || offsets [ 2 * i ] != offsets [ 2 * i + 1 ] ) {
2593
2589
if (offset_capture ) {
2594
2590
add_offset_pair (
2595
2591
return_value , subject , offsets [2 * i ], offsets [2 * i + 1 ], NULL , 0 );
2596
2592
} else {
2597
- ZVAL_STRINGL (& tmp , & subject [ offsets [2 * i ]], match_len );
2593
+ populate_match_value_str (& tmp , subject , offsets [2 * i ], offsets [ 2 * i + 1 ] );
2598
2594
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & tmp );
2599
2595
}
2600
2596
}
2601
2597
}
2602
2598
}
2603
2599
2604
2600
/* Advance to the position right after the last full match */
2605
- start_offset = offsets [1 ];
2601
+ start_offset = last_match_offset = offsets [1 ];
2606
2602
2607
2603
/* If we have matched an empty string, mimic what Perl's /g options does.
2608
2604
This turns out to be rather cunning. First we set PCRE2_NOTEMPTY_ATSTART and try
@@ -2660,18 +2656,18 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
2660
2656
}
2661
2657
2662
2658
last :
2663
- start_offset = ( last_match - subject ) ; /* the offset might have been incremented, but without further successful matches */
2659
+ start_offset = last_match_offset ; /* the offset might have been incremented, but without further successful matches */
2664
2660
2665
2661
if (!no_empty || start_offset < ZSTR_LEN (subject_str )) {
2666
2662
if (offset_capture ) {
2667
2663
/* Add the last (match, offset) pair to the return value */
2668
2664
add_offset_pair (return_value , subject , start_offset , ZSTR_LEN (subject_str ), NULL , 0 );
2669
2665
} else {
2670
2666
/* Add the last piece to the return value */
2671
- if (last_match == subject ) {
2667
+ if (start_offset == 0 ) {
2672
2668
ZVAL_STR_COPY (& tmp , subject_str );
2673
2669
} else {
2674
- ZVAL_STRINGL (& tmp , last_match , subject + ZSTR_LEN (subject_str ) - last_match );
2670
+ populate_match_value_str (& tmp , subject , start_offset , ZSTR_LEN (subject_str ));
2675
2671
}
2676
2672
zend_hash_next_index_insert_new (Z_ARRVAL_P (return_value ), & tmp );
2677
2673
}
0 commit comments