www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4367] New: std.regex: Captures is not a random access range

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

           Summary: std.regex: Captures is not a random access range
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: graham.fawcett gmail.com


--- Comment #0 from Graham Fawcett <graham.fawcett gmail.com> 2010-06-22
06:12:47 PDT ---
From the std.regex documentation:

"Captures captures(). Retrieve the captured parenthesized matches, 
in the form of a random-access range."

The Captures struct is not a random access range, because it is not a
forward range. The following test program fails to compile:

import std.regex;
import std.range;

void main() {
  auto c = match("hello", "[aeiou]").captures;
  alias typeof(c) C;
  static assert (isInputRange!C);   // pass
  static assert (isForwardRange!C); // failure
  static assert (isBidirectionalRange!C);
  static assert (isRandomAccessRange!C);
}

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



--- Comment #1 from Graham Fawcett <graham.fawcett gmail.com> 2010-06-22
08:28:27 PDT ---
Created an attachment (id=673)
proposed patch

This adds .save, .back and .popBack, making Captures a RandomAccessRange.

Note: in my .save implementation, I think it's correct to use the same input,
but to use a saved copy of matches.

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



--- Comment #2 from Graham Fawcett <graham.fawcett gmail.com> 2010-06-22
08:50:01 PDT ---
Hm, did my patch implement 'back' correctly? It's not clear to me
whether it should be this:

  return input[matches[$-1].startIdx .. matches[$-1].endIdx];

(as in my patch), or this:

  size_t end = length - 1;
  return input[matches[end].startIdx .. matches[end].endIdx];

The question arises from the definition of length():

   property size_t length()
  {
      foreach (i; 0 .. matches.length)
      {
          if (matches[i].startIdx >= input.length) return i;
      }
      return matches.length;
  }

So should back() use length() as a limit, or should it return the last
element of matches?

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


Andrei Alexandrescu <andrei metalanguage.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4367


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |dmitry.olsh gmail.com
         Resolution|                            |FIXED


--- Comment #3 from Dmitry Olshansky <dmitry.olsh gmail.com> 2011-06-06
08:10:36 PDT ---
Apparently fixed in version 2.053
https://github.com/D-Programming-Language/phobos/commit/b68db973064ac7ad149cc42c3b4dc5416b576d21

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