www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7962] New: std.regex: Captures.length() returns incorrect value

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

           Summary: std.regex: Captures.length() returns incorrect value
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: markusle gmail.com



PDT ---
It seems that Captures.length() from std.regex returns bogus lengths for empty
captures (I might be using it improperly). Here's a simple example, the second
match object claims length 2 while being empty.

sh-4.2$ uname
Linux

sh-4.2$ dmd | grep "DMD"
DMD64 D Compiler v2.059

sh-4.2$ cat test.d 
import std.regex;
import std.stdio;

int main() {

  auto r = regex(r"( \w+)", "g");

  writeln("match first string  -- looks ok");
  string text1 = " This is a test";
  auto m1 = match(text1, r);
  auto myCapts1 = m1.captures;
  writeln("content:  ", myCapts1);
  writeln("is empty? ", myCapts1.empty());
  writeln("length:   ", myCapts1.length());

  writeln("");
  writeln("match second string -- length seems wrong");
  string text2 = "(his) is a test";
  auto m2 = match(text2, r);
  auto myCapts2 = m2.captures;
  writeln("content:  ", myCapts2);
  writeln("is empty? ", myCapts2.empty());
  writeln("length :  ", myCapts2.length());

  return 0;
}

sh-4.2$ dmd test.d 
sh-4.2$ ./test 
match first string  -- looks ok
content:  [" This", " This"]
is empty? false
length:   2

match second string -- length seems wrong
content:  []
is empty? true
length :  2

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 21 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7962


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |dmitry.olsh gmail.com



14:11:59 PDT ---

 It seems that Captures.length() from std.regex returns bogus lengths for empty
 captures (I might be using it improperly). Here's a simple example, the second
 match object claims length 2 while being empty.
Thanks for the detailed info. The problem is that Captures.length is hardwired to the number of sub captures + 1 which is fine as long as there is a match. For now you may use m.empty ? 0 : m.length as a workaround. Pull: https://github.com/D-Programming-Language/phobos/pull/548 P.S. Usage of e.g. length() is deprecated and fails with -property switch. Omit parens for property members. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7962




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/6c9414c8c9f1df9f2c42229cf1b7eb8bd90d076b
fix Issue 7962  Captures.length() returns incorrect value

https://github.com/D-Programming-Language/phobos/commit/70ad8e4aaeda91d8c1db19b07ac3e3c3db2d23a6


fix Issue 7962  Captures.length() returns incorrect value

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


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

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



00:18:37 PDT ---
Does it need to be combined with another switch to "enforce"?
I think it's -w switch that stands for warnings as errors. Or -wi to just enable them. Strange as I thought -property was independent entity. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 23 2012