Wouldn't it be better if std.string's indexOf/lastIndexOf returned 
haystack.length instead of -1 to indicate "not found"? The -1 is never 
really useful, but needs like this are fairly common:

auto slice = str[str.indexOf(needle)..$];

Which gives you an empty string if needle doesn't exist, which I find is 
usually exactly what I want anyway (and consistent with find's semantics, 
IIRC). But with the current semantics of indexOf/lastIndexOf, the risk of 
the occasional -1 forces the clean code above to be turned into something 
like this:

auto needleIndex = str.indexOf(needle);
auto slice = needleIndex==-1? "" : str[needleIndex..$];

Yuck.


Reply via email to