www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9699] New: strip functions should allow setting custom match character

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699

           Summary: strip functions should allow setting custom match
                    character
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: andrej.mitrovich gmail.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-12
05:40:16 PDT ---
This applies to strip, stripLeft, and stripRight.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-12
05:47:31 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1201

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from bearophile_hugs eml.cc 2013-03-12 06:16:47 PDT ---
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?


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]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-12
06:28:25 PDT ---
(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.
 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699


monarchdodra gmail.com changed:

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


--- Comment #4 from monarchdodra 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: -------
Mar 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|pull                        |
         AssignedTo|andrej.mitrovich gmail.com  |nobody puremagic.com


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-12
14:04:55 PDT ---
I'll work on this some other time unless someone else implements it before me.

Andrei now wants this to be completely generic and put into std.algorithm.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699



--- Comment #6 from bearophile_hugs eml.cc 2013-03-12 14:12:52 PDT ---
(In reply to comment #5)
 I'll work on this some other time unless someone else implements it before me.
 
 Andrei now wants this to be completely generic and put into std.algorithm.

In my code 99% of times I want to strip strings. Only once in a lot of time I'd like to strip a generic 1D array. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com


--- Comment #7 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-05-27
04:33:56 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1311

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699



--- Comment #8 from github-bugzilla puremagic.com 2013-09-27 06:48:45 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/904682ac78e503fef8c57475634a8026bb6d2f20
Fixes Issue 9699 - Implement generic strip/stripLeft/stripRight functions which
accept an element or a predicate.

https://github.com/D-Programming-Language/phobos/commit/8503ed1e2329cd1b14a0e470dbdb12206a0e49a8
Merge pull request #1311 from AndrejMitrovic/Fix9699_2

Issue 9699 - Implement generic strip/stripLeft/stripRight functions

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 27 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9699


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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