#9 SE - replaceAll(regex) is ever caseSensitive

closed-fixed
Other (7)
5
2010-05-13
2010-05-08
Christian Rösch
No

Hello!

There is another thing with replaceAll(). Using it with regex is searching/replacing in a caseSensitive way - ever.
So wholeWord = false and caseSensitive = false and regex = true - that's where I found this issue.

I used this string:

"How much wood would a WOODCHUCK chuck, if a woodchuck COULD CHUCK wood?"

The regex is ".ould" the replacement is "XXXXX"

Find/Replace make this:

"How much wood XXXXX a WOODCHUCK chuck, if a woodchuck XXXXX CHUCK wood?"

ReplaceAll makes this:

"How much wood XXXXX a WOODCHUCK chuck, if a woodchuck COULD CHUCK wood?"

I expect them to be the same ..

I did it with caseSensitive = true and that worked fine.

I would expect that replaceAll and find/replace and markAll have the same results AND if I'd use them with caseSensitive = true in this example it would only find/replace/mark one match (that is already fine) and if I'd use them with caseSensitive = false it would find/replace/mark two ones.

So the thing is that replaceAll is ever caseSensitive.

Notice that this is only about using these methods with regex :)

Thanks!

Discussion

1 2 > >> (Page 1 of 2)
  • Robert Futrell
    Robert Futrell
    2010-05-09

    I've pushed a fix for this. Try checking out revision 192 and re-running your test. The "case sensitive" option should now be honored correctly.

    Note that this patch also makes "replaceAll()" and "replace()" atomic edits. This required them to take RTextAreas instead of JTextAreas as parameters. I figured this was a fair trade off. Although the library used to be usable in any JTextArea, if you're using the RSTA library you're hopefully using RTextArea/RSyntaxTextArea instead. :)

    Anyway, this seemed to fix it for me. Let me know if it lets your tests pass, and I'll mark this one fixed. Then on to the "whole word" issue.

     
  • Robert Futrell
    Robert Futrell
    2010-05-09

    • status: open --> pending
     
    • status: pending --> open
     
  • Hm .. there is a NPE in line 882. Are you interested in getting the tests? Maybe I can email you the tests!?

     
  • Robert Futrell
    Robert Futrell
    2010-05-09

    Sure, send them my way. Thanks!

     
  • Robert Futrell
    Robert Futrell
    2010-05-13

    I believe replaceAll()/regex/case-sensitivity is now working properly together. I created a very simple JUnit test case and put it into the project here:

    http://svn.fifesoft.com/svn/RSyntaxTextArea/RSyntaxTextArea/trunk/test/org/fife/ui/rtextarea/SearchEngineTest.java

    While not very robust, I believe it is sufficient for checking that find, replace and replaceAll all work with match case, whole word, regex, and all combinations of the three. Please check it out, feedback is always welcome.

    I never re-ran with the proposed fixes against your test case; please do so and let me know if there are any problems you're still seeing. I would have committed your test case, or a variation of it, but it was using German (?) characters and I was worried about file encoding issues. I'd prefer only pushing ASCII files into SVN to ensure all files look as expected across all systems.

    Let me know how things look now!

     
  • Robert Futrell
    Robert Futrell
    2010-05-13

    • status: open --> pending
     
  • I ran it with my test and the problems were now fixed.

    But I noticed one thing. Now a word is also a whole word if an ? follows that was different in previous versions. I noticed it because one test case failed when running it against the version 194 from svn.

    I think it isn't a bug if you want it to be as it is right now ;)

    No problem, use your own text and test case .. yes that are German characters but I thought they are ASCII too .. but for me it doesn't matter if you're using your own test case or my test case .. :)

    So I agree with you and I believe that the things are working now.

     
    • status: pending --> open
     
  • Robert Futrell
    Robert Futrell
    2010-05-13

    Awesome, thanks Chriatian! Yes, the new "whole word" criteria is "any non-letter-or-digit surrounding the word" whereas the old criteria was "spaces or tabs surrounding the word". The new criteria is much better, I believe, and matches the behavior of other editors like Eclipse.

    About the German characters, I guess by ASCII I meant "code points <= 127". I thought some German characters were in the extended range, < 256, but I could be wrong about that.

     
1 2 > >> (Page 1 of 2)