www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5201] New: std.string.indexOf and std.algorithm.indexOf return different things for narrow strings

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

           Summary: std.string.indexOf and std.algorithm.indexOf return
                    different things for narrow strings
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrei metalanguage.com



10:56:43 PST ---
std.algorithm.indexOf returns logical position because it uses the forward
range interface, and std.string.indexOf returns the physical position.

This is potentially confusing (the semantics of a program depends on its
imports).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5201


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5201


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PST ---
I would think that you'd want character arrays and indexOf to always function
like it does in std.string - the index is the index of the array, but
comparison is done by code point rather than code unit. So, then I would think
that the correct solution would be either to special case
std.algorithm.indexOf() for all character arrays (and deprecated
std.string.indexOf()) or to make it so that it doesn't work with character
arrays and have std.string.indexOf() deal with them instead. There could be a
good reason that I haven't thought of to not to do it that way though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5201




PST ---
Glancing at std.string.indexOf() again, it has different parameters than
std.algorithm - dealing with case sensitivity and whatnot. It also takes a
dchar rather than a string or some variety to find the index of, which differs
from what std.algorithm does - since it uses startsWith(). Given the
differences, I'd argue in favor of just making std.algorithm.indexOf() not
working with char arrays. However, it would be nice if std.string.indexOf()
were made to work with strings rather than dchar (or in addition to it), and it
doesn't take a predicate like std.algorithm's indexOf() does, and those could
be useful.

Ultimately, I think that the two functions should be made to work more
similarly than they do on more than just what type of index that they're
returning - particularly since a _lot_ of programs are going to be importing
both std.algorithm and std.string (most of mine definitely do). Fixing the
index issue though is the highest priority in that it changes behavior based on
imports whereas the other differences are major enough to result in compilation
errors if you use the wrong one.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5201


Andrei Alexandrescu <andrei erdani.com> changed:

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



PST ---
std.algorithm.indexOf has been deprecated.

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