Fix #74264: grapheme_sttrpos() broken for negative offsets#7189
Fix #74264: grapheme_sttrpos() broken for negative offsets#7189cmb69 wants to merge 4 commits intophp:PHP-7.4from
Conversation
We must not assume that `usearch_last()` gives the proper result for negative offsets. Instead we'd need to continue to search backwards (`usearch_previous`) until we find a proper match. However, apparently searching backwards is broken, so we work around by searching forward from the start of the string until we pass the `offset_pos`, and then use the previous result.
Broken how? |
|
For the test string |
|
@cmb69 Looking through the docs, I believe this should be a matter of setting the USEARCH_OVERLAP attribute. |
|
Thanks, that improves the backward search, but there is still an issue at the end of the string; e.g. |
|
I've tried a lot of different variants, but in the end I can only agree with your conclusion that usearch_previous/preceding are buggy. It looks like generally the starting offset of the match must be strictly lower than the starting position, but if the match is at the very end of the string, then the match can be at the starting position. I think we'll have to go back to your first implementation :( |
This reverts commit 7f75d59.
We must not assume that
usearch_last()gives the proper result fornegative offsets. Instead we'd need to continue to search backwards
(
usearch_previous) until we find a proper match. However, apparentlysearching backwards is broken, so we work around by searching forward
from the start of the string until we pass the
offset_pos, and thenuse the previous result.