Phobos: Arbitrary delimiter variants of (std.string) stripLeft and stripRight

Jonathan M Davis jmdavisProg at gmx.com
Tue Jun 26 21:40:24 PDT 2012


On Saturday, June 23, 2012 20:04:11 Chad J wrote:
> I'm not exactly sure what the arbitrary delimiter variants of stripLeft
> and stripRight are, but they should be referenced in the documentation
> of those functions.  And if they don't exist, why don't we have them?

You know, you can use find for the same thing quite easily (heck, you can use 
find instead of the current version of strip quite easily), so I'm not sure 
that this buys us much. It is a bit ugly to deal with stripRight that way, but 
if anything, I think that's an argument for adding rfind rather than an 
overload for strip.

auto strippedLeft = find!"a != b"(str, delim);
auto strippedRight = retro(find!"a != b"(retro(str), delim));
auto stripped = find!"a != b"(retro(find!"a != b"(retro(str), delim), delim);

If we had rfind, it could be

auto stripped = find!"a != b"(rfind!"a != b"(str, delim), delim);

Stripping whitespace is done often enough that strip, stripLeft, and 
stripRight are is merited, but I'm not convinced that stripping anything other 
than whitespace is common enough to merit it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list