www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5019] New: In std.regex, empty capture at end of string causes error

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

           Summary: In std.regex, empty capture at end of string causes
                    error
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: petevik38 yahoo.com.au



An empty capture before the end of the string seems to work fine:

    auto m = match( "abc", "ab(.*)c" );
    writefln( "'%s'", m.captures[1] );

-> ''


An empty capture at the end of a string results in the following assert error:

    auto m = match( "abc", "abc(.*)" );
    writefln( "'%s'", m.captures[1] );

->
core.exception.AssertError c:\dmd2\windows\bin\..\..\src\phobos\std\regex.d(1705):
1

In Captures.length :

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

The test will fail for an empty capture at the end because startIdx == endIdx
== input.length. This seems like it should be a valid case and the following
change seems to resolve the issue:

                if (matches[i].startIdx > input.length) return i;

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


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 next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5019


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86_64                      |x86



---
Mass migration of bugs marked as x86-64 to just x86.  The platform run on isn't
what's relevant, it's if the app is a 32 or 64 bit app.

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


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

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



08:18:29 PDT ---
*** This issue has been marked as a duplicate of issue 5511 ***

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