Reversing a string is what I would consider basic string operations, but I also expect it not to break emoji and other grapheme clusters.
Nothing is easy.
Reversing a string is what I would consider basic string operations, but I also expect it not to break emoji and other grapheme clusters.
Nothing is easy.
Tbh I can't think of a time when I've actually needed to do that.
I have never once wanted to actually do this in real code, with real strings.
Furthermore, the few times I've tried to do something like this by being cute and encoding data in a string, I never get outside the ASCII character set.
find ... | rev | sort | rev > sorted-filelist
I had several directories and I wanted to pull out the unique list of certain files (TrueType fonts) across all of them, regardless of which subdirs they were in. (I'm omitting the find CLI args for clarity; the command just finds all the *.ttf (case-insensitive) files in the dirs.)By reversing the lines before sorting them (and un-reversing them) they come out sorted and grouped by filename.
Recently I rewrote the codepoint reverse function to make it faster. The trick is to not write codepoints, but copy the bytes.
One the first attempt I introduced two bugs.
I wonder: several comments are saying it hardly makes any sense to reverse a string but... Certainly there are useful algorithms out there which do work by, at some point, reversing strings no!? I mean: not just for the sake of reversing it but for lookup/parsing or I don't know what.