php_mb_regex_t *re;
OnigRegion *regs = NULL;
char *string;
- OnigUChar *pos;
+ OnigUChar *pos, *chunk_pos;
int string_len;
int n, err;
RETURN_FALSE;
}
- if (count == 0) {
- count = 1;
+ if (count > 0) {
+ count--;
}
/* create regex pattern buffer */
array_init(return_value);
- pos = (OnigUChar *)string;
+ chunk_pos = pos = (OnigUChar *)string;
err = 0;
regs = onig_region_new();
/* churn through str, generating array entries as we go */
- while ((--count != 0) &&
- (err = onig_search(re, (OnigUChar *)string, (OnigUChar *)(string + string_len), pos, (OnigUChar *)(string + string_len), regs, 0)) >= 0) {
- if (regs->beg[0] == regs->end[0]) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular expression");
+ while (count != 0 && (pos - (OnigUChar *)string) < string_len) {
+ int beg, end;
+ err = onig_search(re, (OnigUChar *)string, (OnigUChar *)(string + string_len), pos, (OnigUChar *)(string + string_len), regs, 0);
+ if (err < 0) {
break;
}
-
+ beg = regs->beg[0], end = regs->end[0];
/* add it to the array */
- if (regs->beg[0] < string_len && regs->beg[0] >= (pos - (OnigUChar *)string)) {
- add_next_index_stringl(return_value, (char *)pos, ((OnigUChar *)(string + regs->beg[0]) - pos), 1);
+ if ((pos - (OnigUChar *)string) < end) {
+ if (beg < string_len && beg >= (chunk_pos - (OnigUChar *)string)) {
+ add_next_index_stringl(return_value, (char *)chunk_pos, ((OnigUChar *)(string + beg) - chunk_pos), 1);
+ --count;
+ } else {
+ err = -2;
+ break;
+ }
+ /* point at our new starting point */
+ chunk_pos = pos = (OnigUChar *)string + end;
} else {
- err = -2;
- break;
- }
- /* point at our new starting point */
- n = regs->end[0];
- if ((pos - (OnigUChar *)string) < n) {
- pos = (OnigUChar *)string + n;
- }
- if (count < 0) {
- count = 0;
+ pos++;
}
onig_region_free(regs, 0);
}
}
/* otherwise we just have one last element to add to the array */
- n = ((OnigUChar *)(string + string_len) - pos);
+ n = ((OnigUChar *)(string + string_len) - chunk_pos);
if (n > 0) {
- add_next_index_stringl(return_value, (char *)pos, n, 1);
+ add_next_index_stringl(return_value, (char *)chunk_pos, n, 1);
} else {
add_next_index_stringl(return_value, "", 0, 1);
}
}
-- Iteration 10 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
}
-- Iteration 11 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
}
-- Iteration 13 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
}
-- Iteration 15 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
}
-- Iteration 16 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
}
-- Iteration 17 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
}
-- Iteration 22 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
}
-- Iteration 23 --
-
-Warning: mb_split(): Empty regular expression in %s on line %d
array(1) {
[0]=>
string(13) "a b c d e f g"
Warning: mb_split() expects parameter 1 to be string, resource given in %s on line %d
bool(false)
-Done
\ No newline at end of file
+Done