This comes up every now and again, and lots of frameworks implement
their own versions. I’m thinking
of submitting an RCR for something functionally equivalent to the
following to be incorporated into
the base library:
index(aString) == 0
rindex(aString) == length - aString.length
Of course, the real implementation would have much better performance.
The advantage of including
something like this is that these common functions can be made both
high-performance and readable.