From: <k_s...@us...> - 2008-08-23 07:52:01
|
Revision: 13400 http://jedit.svn.sourceforge.net/jedit/?rev=13400&view=rev Author: k_satoda Date: 2008-08-23 07:51:57 +0000 (Sat, 23 Aug 2008) Log Message: ----------- Enabled reverse regex search. (SF.net patch #1923613) There is a known problem with "$", but accepting this looks a good way for now because this is a very basic feature. The problem will be addressed later as a bug. Modified Paths: -------------- jEdit/trunk/doc/CHANGES.txt jEdit/trunk/org/gjt/sp/jedit/jedit_gui.props jEdit/trunk/org/gjt/sp/jedit/search/PatternSearchMatcher.java jEdit/trunk/org/gjt/sp/jedit/search/SearchAndReplace.java jEdit/trunk/org/gjt/sp/jedit/search/SearchBar.java jEdit/trunk/org/gjt/sp/jedit/search/SearchDialog.java Modified: jEdit/trunk/doc/CHANGES.txt =================================================================== --- jEdit/trunk/doc/CHANGES.txt 2008-08-23 04:19:46 UTC (rev 13399) +++ jEdit/trunk/doc/CHANGES.txt 2008-08-23 07:51:57 UTC (rev 13400) @@ -3,7 +3,7 @@ {{{ Version 4.3pre16 Thanks to Bj\xF6rn "Vampire" Kautler, Kazutoshi Satoda, Alan Ezust, -and Shlomy Reinstein for contributing to this release. +Shlomy Reinstein, and Greg Merrill for contributing to this release. {{{ Bug Fixes @@ -16,6 +16,10 @@ {{{ Miscellaneous - Moved buffer list sorting options from General to View Option Pane with other bufferset options. (Alan Ezust) + +- Enabled reverse regex search. (SF.net patch #1923613 - Greg Merrill) + NOTE: There is a known problem with "$". + }}} {{{ Docker Plugin features merged into jEdit Core Modified: jEdit/trunk/org/gjt/sp/jedit/jedit_gui.props =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/jedit_gui.props 2008-08-23 04:19:46 UTC (rev 13399) +++ jEdit/trunk/org/gjt/sp/jedit/jedit_gui.props 2008-08-23 07:51:57 UTC (rev 13400) @@ -1438,12 +1438,6 @@ (if applicable) are set correctly. #}}} -#{{{ Reverse regular expression search not supported dialog -regexp-reverse.title=Not Supported -regexp-reverse.message=Cannot search backwards for a regular expression.\n\ - Either search forwards or disable regular expressions. -#}}} - #{{{ Can only search local directories dialog remote-dir-search.title=Non-Local Directory Chosen remote-dir-search.message=You have elected to search a non-local directory.\n\ Modified: jEdit/trunk/org/gjt/sp/jedit/search/PatternSearchMatcher.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/search/PatternSearchMatcher.java 2008-08-23 04:19:46 UTC (rev 13399) +++ jEdit/trunk/org/gjt/sp/jedit/search/PatternSearchMatcher.java 2008-08-23 07:51:57 UTC (rev 13400) @@ -24,6 +24,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.gjt.sp.util.ReverseCharSequence; + /** * A regular expression string matcher using java.util.regex. * @see java.util.regex.Pattern @@ -74,8 +76,10 @@ * @param firstTime If false and the search string matched at the * start offset with length zero, automatically * find next match - * @param reverse Unsupported for PatternSearchMatcher. Should - * always be "false". + * @param reverse If true find match prior to current match + * (this is done by searching from the beginning to + * just prior to the current match, so will be inefficient + * for large buffers) * * @return A {@link SearchMatcher.Match} object. * @since jEdit 4.3pre5 @@ -83,6 +87,19 @@ public SearchMatcher.Match nextMatch(CharSequence text, boolean start, boolean end, boolean firstTime, boolean reverse) { + // "For the mean time, there is no way to automatically generate a sexeger" + // + // http://japhy.perlmonk.org/sexeger/sexeger.html + // + // So ... for reverse regex searches we will search + // the string in the forward direction and + // return the last match. + + // Since we search the String in the forward direction, + // (even for reverse searches) un-reverse the ReverseCharSequence. + if (text instanceof ReverseCharSequence) + text = ((ReverseCharSequence)text).baseSequence(); + if (re == null) re = Pattern.compile(pattern, flags); @@ -90,31 +107,50 @@ if (!match.find()) return null; - // if we're not at the start of the buffer, and the pattern - // begins with "^" and matched the beginning of the region - // being matched, ignore the match and try the next one. - if (!start && match.start() == 0 - && re.pattern().charAt(0) == '^' && !match.find()) - return null; + while (true) { + // if we're not at the start of the buffer, and the pattern + // begins with "^" and matched the beginning of the region + // being matched, ignore the match and try the next one. + if (!start && match.start() == 0 + && re.pattern().charAt(0) == '^' && !match.find()) + return null; + + // similarly, if we're not at the end of the buffer and we + // match the end of the text, and the pattern ends with a "$", + // return null. + if (!end && match.end() == (text.length() - 1) + && pattern.charAt(pattern.length() - 1) == '$') + return null; + + returnValue.substitutions = new String[match.groupCount() + 1]; + for(int i = 0; i < returnValue.substitutions.length; i++) + { + returnValue.substitutions[i] = match.group(i); + } + + int _start = match.start(); + int _end = match.end(); + + returnValue.start = _start; + returnValue.end = _end; + + // For non-reversed searches, we break immediately + // to return the first match. For reversed searches, + // we continue until no more matches are found + if (!reverse || !match.find()) { + break; + } + } - // similarly, if we're not at the end of the buffer and we - // match the end of the text, and the pattern ends with a "$", - // return null. - if (!end && match.end() == (text.length() - 1) - && pattern.charAt(pattern.length() - 1) == '$') - return null; - - returnValue.substitutions = new String[match.groupCount() + 1]; - for(int i = 0; i < returnValue.substitutions.length; i++) - { - returnValue.substitutions[i] = match.group(i); + if (reverse) { + // The caller assumes we are searching a reversed + // CharSegment, so we need to reverse the indices + // before returning + int len = returnValue.end - returnValue.start; + returnValue.start = text.length() - returnValue.end; + returnValue.end = returnValue.start + len; } - int _start = match.start(); - int _end = match.end(); - - returnValue.start = _start; - returnValue.end = _end; return returnValue; } //}}} Modified: jEdit/trunk/org/gjt/sp/jedit/search/SearchAndReplace.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/search/SearchAndReplace.java 2008-08-23 04:19:46 UTC (rev 13399) +++ jEdit/trunk/org/gjt/sp/jedit/search/SearchAndReplace.java 2008-08-23 07:51:57 UTC (rev 13400) @@ -447,11 +447,6 @@ } boolean _reverse = reverse && fileset instanceof CurrentBufferSet; - if(_reverse && regexp) - { - GUIUtilities.error(comp,"regexp-reverse",null); - return false; - } try { Modified: jEdit/trunk/org/gjt/sp/jedit/search/SearchBar.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/search/SearchBar.java 2008-08-23 04:19:46 UTC (rev 13399) +++ jEdit/trunk/org/gjt/sp/jedit/search/SearchBar.java 2008-08-23 07:51:57 UTC (rev 13400) @@ -211,12 +211,6 @@ //{{{ Incremental search else { - if(reverse && SearchAndReplace.getRegexp()) - { - GUIUtilities.error(view,"regexp-reverse",null); - return; - } - // on enter, start search from end // of current match to find next one int start; Modified: jEdit/trunk/org/gjt/sp/jedit/search/SearchDialog.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/search/SearchDialog.java 2008-08-23 04:19:46 UTC (rev 13399) +++ jEdit/trunk/org/gjt/sp/jedit/search/SearchDialog.java 2008-08-23 07:51:57 UTC (rev 13400) @@ -691,8 +691,7 @@ && !searchSelection.isSelected()); boolean reverseEnabled = !hyperSearch.isSelected() - && searchCurrentBuffer.isSelected() - && !regexp.isSelected(); + && searchCurrentBuffer.isSelected(); searchBack.setEnabled(reverseEnabled); searchForward.setEnabled(reverseEnabled); if(!reverseEnabled) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |