krakjoe / ustring

UnicodeString for PHP7
Other
64 stars 7 forks source link

remove $offset from indexOf() and lastIndexOf() #25

Open Wes0617 opened 8 years ago

Wes0617 commented 8 years ago

they are redundant with substring(). there are better ways to avoid unnecessary copies [stringbuilder is one, or interning], provided that we care of this kind of optimizations

hikari-no-yume commented 8 years ago

Redundant maybe, but is that a good enough reason to drop it? Being able to specify an offset when finding an index is a common feature of string libraries.

hikari-no-yume commented 8 years ago

In fact, I'd go so far as to say it's essential. It's not a deduplication trick, it's a means to specify where you are searching in a string. You need this when, for example, searching for multiple occurences of a string within a string. You could truncate the string each time, but this wastes memory and CPU time, and requires you to do arithmetic to find the position in the original string.