sπ‘ πβ now returns grapheme index instead of UTF-8 index
sπ‘ πβ now returns grapheme index instead of UTF-8 index
Fixes #208
Thanks for immediately opening a PR to fix this! Unfortunately, your implementation runs in O(n) in terms of memory as πͺ allocates memory for each substring. Do you think you could maybe create an overload of πΌ that takes a start index from which to compare? Then no substring would be needed.
OK I'll look into using that approach. Thanks for the feedback!
@thbwd I've started the approach you suggested, but it looks like I'm running into the same problem that caused the issue to begin with. Once I get over to the C++ side, the sStringBeginsWith code uses a memory comparison between string->characters.get(), beginning->characters.get(). There isn't enough context here to be able to determine where in the string to start comparing since we would have to get the graphemes, measure them, and then start the memory comparison at that calculated index. And since this would still be done in a loop, this code would have to be called multiple times.
I'm wondering if there would be a better approach involving passing not only the source string, but also the source string in grapheme array form, allowing that operation to only be done once.
OK @thbwd I believe this is ready to be reviewed again.