krakjoe / ustring

UnicodeString for PHP7
Other
64 stars 7 forks source link

String reversal works on code points #19

Open hikari-no-yume opened 9 years ago

hikari-no-yume commented 9 years ago

Currently, string reversal works on code points, it doesn't care what kind. So it won't reverse strings containing combining characters properly.

We could quite simply implement the Missy Elliot algorithm that @mathiasbynens came up with, and then it'd do what people expect.

Thoughts?

mathiasbynens commented 9 years ago

Depending on your use case though, the algorithm may not be sufficient, sadly. See https://github.com/mathiasbynens/esrever/issues/5.

hikari-no-yume commented 9 years ago

Ah, that's unfortunate. PHP has grapheme_ functions for manipulating grapheme clusters, and that just uses ICU I believe, so we can probably just use ICU's handling of this.

hikari-no-yume commented 9 years ago

Since it doesn't look like this'll be fixed in time for PHP 7's release, I suggest we rename the function and explicitly note in the documentation that it doesn't care for combining chars etc.

That way, we won't break anything if we later introduce a better algorithm.