[Issue 9699] strip functions should allow setting custom match character

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 12 07:04:41 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9699


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #4 from monarchdodra at gmail.com 2013-03-12 07:04:38 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> > Regarding this code I have two comments:     
> > 
> > C[] stripRight(C)(C[] str)
> >     if(isSomeChar!C)
> > {
> >     foreach_reverse(i, dchar c; str)
> >     {
> >         if(!std.uni.isWhite(c))
> >             return str[0 .. i + codeLength!C(c)];
> >     }
> > 
> >     return str[0 .. 0];
> > }
> > 
> > 
> > 1) Isn't it enough a "return null;" at the end?
> 
> It's enough but it's different. At the call site !is null checks will depend on
> what is returned here.

Further more, "strip" returns a "sub slice" of the original slice. If you
return null, then "sameHead(str, stripRight(str))" will not be guaranteed.

Very very minor points, but I see no reason to do things wrong when you can do
them right.

besides, str[0 .. 0] doesn't trigger bounds checking, so there is no overhead
compared to null anyways.

> > 2) When I see such string functions I often think about stripping leading
> > values from a generic 1D array:
> > [0,0,0,0,10,7,1234,0]
> 
> I don't know what is being asked here.

He's basically saying there's no real reason for strip to be limited to just
strings, and could operate on arrays or ranges.

I'd kind of agree, but given our current clusterfuck with splitter, I think we
need to think long and hard before adding anything.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list