classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] java.util.regex.Matcher.matches() fix


From: Mark Wielaard
Subject: Re: [cp-patches] java.util.regex.Matcher.matches() fix
Date: Sun, 06 Feb 2005 18:13:11 +0100

Hi Timo,

On Fri, 2005-02-04 at 22:55 +0200, Timo Juhani Lindfors wrote:
> java.util.regex.Pattern.matches("b", "ab")

Thanks for the test. I have added it plus some more tests to Mauve as
gnu.testlet.java.util.regex.Pattern.matches.

> matches() shouldn't call find() because find() returns true if _any_
> part of the input matches and matches() should return true only if the
> _whole_ input matches.

Good catch.

> The attached patch fixes the problem for me but I'm very new to GNU
> classpath so I might have missed something. Could you please take a
> look at the patch and commit if you agree?

Hint: Try running mauve. It already had some tests that used matches()
which failed with your patch. We need to actually make sure that the
Matches can be queried about the match result (if any). So I
reimplemented the method through lookingAt() which already almost does
what we want. It just doesn't test that the end of the match is at the
end of the input. And found a bug in lookingAt(). We were not setting
the new position as required. Oops.

This patch fixes all these issues. All new mauve tests succeed.
No regressions.

2005-02-06  Mark Wielaard  <address@hidden>

        Reported by Timo Lindfors <address@hidden>
        java/util/regex/Matcher.java (lookingAt): Set position when
        match found.
        (matches): Implemented through lookingAt().

Committed.

Thanks,

Mark
Index: java/util/regex/Matcher.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/regex/Matcher.java,v
retrieving revision 1.7
diff -u -r1.7 Matcher.java
--- java/util/regex/Matcher.java        15 Nov 2004 14:13:26 -0000      1.7
+++ java/util/regex/Matcher.java        6 Feb 2005 17:09:55 -0000
@@ -212,7 +212,10 @@
     if (match != null)
       {
        if (match.getStartIndex() == 0)
-         return true;
+         {
+           position = match.getEndIndex();
+           return true;
+         }
        match = null;
       }
     return false;
@@ -230,7 +233,13 @@
    */
   public boolean matches ()
   {
-    return find(0);
+    if (lookingAt())
+      {
+       if (position == input.length())
+         return true;
+       match = null;
+      }
+    return false;
   }
   
   /**

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]