www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1590] New: std.string.startsWith and endsWith please

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

           Summary: std.string.startsWith and endsWith please
           Product: D
           Version: 2.006
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: wbaxter gmail.com


These would be very nice to have in Phobos' std.string.
Java's strings have them (startsWith, endsWith)
Python's strings have them (startswith, endswith)
Ruby strings have them (starts_with, ends_with)
Perl maybe doesn't have it but perl has ~=/^xxx/ and ~=/xxx$/.

Don't let D be the only one without!

They're simple functions but oft-used.


-- 
Oct 16 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590


wbaxter gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement




-- 
Oct 16 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com
             Status|NEW                         |ASSIGNED




-- 
Oct 16 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|bugzilla digitalmars.com    |andrei metalanguage.com
             Status|ASSIGNED                    |NEW




-- 
Oct 16 2007
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED




------- Comment #1 from andrei metalanguage.com  2007-10-19 13:07 -------
The functions hasPrefix(E1[] longer, E2[] shorter) and hasSuffix(E1[] longer,
E2[] shorter) will be part of the next minor release and work with all sensible
combinations of E1 and E2.


-- 
Oct 19 2007
next sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1590
 
 
 andrei metalanguage.com changed:
 
            What    |Removed                     |Added
 ----------------------------------------------------------------------------
              Status|NEW                         |ASSIGNED
 
 
 
 
 ------- Comment #1 from andrei metalanguage.com  2007-10-19 13:07 -------
 The functions hasPrefix(E1[] longer, E2[] shorter) and hasSuffix(E1[] longer,
 E2[] shorter) will be part of the next minor release and work with all sensible
 combinations of E1 and E2.
 
 

Sounds good, but what module? Doesn't seem to have much reason to be in std.string if it works with any types. Perhaps it's time std got an array utils module with generic array manipulation functions? (A la cashew.utils.array). You know with "advanced" functionality like removing an item from an array, etc. And if it's not going into std.string, I think there's a case to be made that std.string should still have a startsWith and endsWith (that just alias hasPrefix/hasSuffix) because std.string is where people will look for it and those are the names people will expect. Either way I'll be happy to have the functionality in the std library. :-) --bb
Oct 19 2007
prev sibling parent Derek Parnell <derek psych.ward> writes:
On Fri, 19 Oct 2007 18:07:23 +0000 (UTC), d-bugmail puremagic.com wrote:

 http://d.puremagic.com/issues/show_bug.cgi?id=1590
 
 andrei metalanguage.com changed:
 
            What    |Removed                     |Added
 ----------------------------------------------------------------------------
              Status|NEW                         |ASSIGNED
 
 ------- Comment #1 from andrei metalanguage.com  2007-10-19 13:07 -------
 The functions hasPrefix(E1[] longer, E2[] shorter) and hasSuffix(E1[] longer,
 E2[] shorter) will be part of the next minor release and work with all sensible
 combinations of E1 and E2.

And I assume it returns a boolean? What happens in the edge cases? Such as hasPrefix("abc", "abc"); hasPrefix("abc", ""); hasPrefix("", "abc"); hasPrefix("", ""); -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Oct 19 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590





------- Comment #2 from andrei metalanguage.com  2007-10-19 14:52 -------
The best approach would be to define std.algorithm and put the two functions in
there. As for terminology, google indeed reveals that startsWith and endsWith
are much more popular, so I'll commit to these names.


-- 
Oct 19 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590





------- Comment #3 from wbaxter gmail.com  2007-10-19 14:58 -------
Just for the record, Andrei's reply above was a response to this NG post:

"""
Sounds good, but what module?  Doesn't seem to have much reason to be in
std.string if it works with any types.  Perhaps it's time std got an array
utils module with generic array manipulation functions?  (A la
cashew.utils.array).   You know with "advanced" functionality like removing an
item from an array, etc.

And if it's not going into std.string, I think there's a case to be made that
std.string should still have a startsWith and endsWith (that just alias
hasPrefix/hasSuffix) because std.string is where people will look for it and
those are the names people will expect.
"""


-- 
Oct 19 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590





------- Comment #4 from wbaxter gmail.com  2007-10-19 15:06 -------
(In reply to comment #2)
 The best approach would be to define std.algorithm and put the two functions in
 there. As for terminology, google indeed reveals that startsWith and endsWith
 are much more popular, so I'll commit to these names.

Seems reasonable. Things in there will only work on objects that support the T[] random-access interface for now (and probably only actual D arrays?) but can be expanded later to include iterators if Phobos ever defines a standard for those. --
Oct 19 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1590


andrei metalanguage.com changed:

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




-- 
Mar 06 2008