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

Chad J chadjoan at __spam.is.bad__gmail.com
Sat Jun 23 17:57:04 PDT 2012


On 06/23/2012 08:25 PM, Jonathan M Davis wrote:
> 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?
>
> There are no such variants. They could be added, but they don't currently
> exist.
>
>> I was looking around for trimLeft and trimRight, but no luck.
>
> trim and strip are the same thing. Having both would be bad design. It's
> understandable if you were looking for trim first, since a library could go
> with either name, and you probably have seen others using trim, but we chose
> strip, and we're not going to have both.
>

I've seen them used to differentiate between whitespace and 
any-delimiter variants in other places, and the vocabulary seems to be 
used entirely inconsistently.  I just kind of run under the assumption 
that trim|strip mean remove /something/ from the right|left side of a 
given string.  The /something/ may or may not be whitespace or some 
delimiter of your choosing depending on what language you are in.

So yeah, I'm all for using something besides "trim". ;)

>> chomp
>> seems to be the arbitrary delimiter variant of trimRight, but then there
>> is no chompLeft.
>
> chompPrefix is chompLeft. And no, _neither_ is the delimiter variant of
> stripLeft or stripRight. stripRight with an arbitrary delimiter would remove
> all instances of that delimiter from the right-hand side of the array (and
> that delimiter would have to be a single character), whereas chomp takes a
> substring and removes _exactly_ that substring. The same would go for
> stripLeft and chompPrefix.
>

Ah.  Looks like a doc rewrite may be in order (and add unittests/examples!):

Returns s sans the trailing delimiter, if any. If no delimiter is given, 
then any trailing '\r', '\n', "\r\n", std.uni.lineSep, or 
std.uni.paraSeps are removed.

My parse of this: "any trailing ...s are removed."

I took the plural to mean that more than one newline/separator may be 
removed.

It should parse like this: "one trailing ... is removed."

>> If we had chompLeft I'd expect chompRight to exist and
>> chomp to remove both the left and right parts.
>>
>> There are also no examples/unittests in the documentation on the website
>> for stripLeft, stripRight, chomp, or a bunch of others.
>
> They could be added.
>
> - Jonathan M Davis

I would say "should be added" myself, given how bread-and-butter this 
stuff is for me (at least at work).  I had to write all of those myself 
when I started using this Synergy/DE|DBL language at work, and it would 
be just silly to have to do that in a powerful language like D.

I'd add all of this stuff myself except that 
http://forum.dlang.org/thread/js5nl8$h94$1@digitalmars.com


More information about the Digitalmars-d mailing list