Modifier and Type | Method and Description |
---|---|
static boolean |
find(JTextArea textArea,
String text,
boolean forward,
boolean matchCase,
boolean wholeWord,
boolean regex)
Finds the next instance of the string/regular expression specified
from the caret position.
|
protected static String |
getFindInText(JTextArea textArea,
int start,
boolean forward)
Returns the text in which to search, as a string.
|
protected static List |
getMatches(Matcher m,
String replaceStr)
This method is called internally by
getNextMatchPosRegExImpl and is used to get the locations
of all regular-expression matches, and possibly their replacement
strings. |
static int |
getNextMatchPos(String searchFor,
String searchIn,
boolean forward,
boolean matchCase,
boolean wholeWord)
Searches
searchIn for an occurrence of
searchFor either forwards or backwards, matching
case or not. |
protected static int |
getNextMatchPosImpl(String searchFor,
String searchIn,
boolean goForward,
boolean matchCase,
boolean wholeWord)
Actually does the work of matching; assumes searchFor and searchIn
are already upper/lower-cased appropriately.
|
static Point |
getNextMatchPosRegEx(String regEx,
CharSequence searchIn,
boolean goForward,
boolean matchCase,
boolean wholeWord)
Searches
searchIn for an occurrence of regEx
either forwards or backwards, matching case or not. |
protected static Object |
getNextMatchPosRegExImpl(String regEx,
CharSequence searchIn,
boolean goForward,
boolean matchCase,
boolean wholeWord,
String replaceStr)
Searches
searchIn for an occurrence of regEx
either forwards or backwards, matching case or not. |
protected static org.fife.ui.rtextarea.RegExReplaceInfo |
getRegExReplaceInfo(String regEx,
String searchIn,
boolean goForward,
boolean matchCase,
boolean wholeWord,
String replacement)
Returns information on how to implement a regular expression "replace"
action in the specified text with the specified replacement string.
|
static String |
getReplacementText(Matcher m,
CharSequence template)
Called internally by
getMatches() . |
protected static int |
makeMarkAndDotEqual(JTextArea textArea,
boolean forward)
Makes the caret's dot and mark the same location so that, for the
next search in the specified direction, a match will be found even
if it was within the original dot and mark's selection.
|
protected static boolean |
regexReplace(JTextArea textArea,
String toFind,
String replaceWith,
boolean forward,
boolean matchCase,
boolean wholeWord)
Finds the next instance of the regular expression specified from
the caret position.
|
static boolean |
replace(RTextArea textArea,
String toFind,
String replaceWith,
boolean forward,
boolean matchCase,
boolean wholeWord,
boolean regex)
Finds the next instance of the text/regular expression specified from
the caret position.
|
static int |
replaceAll(RTextArea textArea,
String toFind,
String replaceWith,
boolean matchCase,
boolean wholeWord,
boolean regex)
Replaces all instances of the text/regular expression specified in
the specified document with the specified replacement.
|
public static boolean find(JTextArea textArea, String text, boolean forward, boolean matchCase, boolean wholeWord, boolean regex) throws PatternSyntaxException
textArea
- The text area in which to search.text
- The string literal or regular expression to search for.forward
- Whether to search forward from the caret position or
backward from it.matchCase
- Whether the search should be case-sensitive.wholeWord
- Whether there should be spaces or tabs on either side
of the match.regex
- Whether text
is a Java regular expression to
search for.PatternSyntaxException
- If regex
is
true
but text
is not a valid regular
expression.replace(org.fife.ui.rtextarea.RTextArea, java.lang.String, java.lang.String, boolean, boolean, boolean, boolean)
,
regexReplace(javax.swing.JTextArea, java.lang.String, java.lang.String, boolean, boolean, boolean)
protected static String getFindInText(JTextArea textArea, int start, boolean forward)
protected static List getMatches(Matcher m, String replaceStr)
getNextMatchPosRegExImpl
and is used to get the locations
of all regular-expression matches, and possibly their replacement
strings.Returns either:
RegExReplaceInfo
s describing the matches
found by the matcher and the replacement strings for each.
replacement
is null
, this method call is
assumed to be part of a "find" operation and points are returned. If
if is non-null
, it is assumed to be part of a "replace"
operation and the RegExReplaceInfo
s are returned.m
- The matcher.replaceStr
- The string to replace matches with. This is a
"template" string and can contain captured group references in
the form "${digit}
".IndexOutOfBoundsException
- If replaceStr
references
an invalid group (less than zero or greater than the number of
groups matched).public static final int getNextMatchPos(String searchFor, String searchIn, boolean forward, boolean matchCase, boolean wholeWord)
searchIn
for an occurrence of
searchFor
either forwards or backwards, matching
case or not.searchFor
- The string to look for.searchIn
- The string to search in.forward
- Whether to search forward or backward in
searchIn
.matchCase
- If true
, do a case-sensitive search for
searchFor
.wholeWord
- If true
, searchFor
occurrences embedded in longer words in searchIn
don't count as matches.-1
if no
match was found.getNextMatchPosImpl(java.lang.String, java.lang.String, boolean, boolean, boolean)
,
getNextMatchPosRegEx(java.lang.String, java.lang.CharSequence, boolean, boolean, boolean)
protected static final int getNextMatchPosImpl(String searchFor, String searchIn, boolean goForward, boolean matchCase, boolean wholeWord)
FindInFilesDialog
; since it repeatedly calls
this method instead of getNextMatchPos
, it gets better
performance as it no longer has to allocate a lower-cased string for
every call.searchFor
- The string to search for.searchIn
- The string to search in.goForward
- Whether the search is forward or backward.matchCase
- Whether the search is case-sensitive.wholeWord
- Whether only whole words should be matched.-1
if no
match was found.public static Point getNextMatchPosRegEx(String regEx, CharSequence searchIn, boolean goForward, boolean matchCase, boolean wholeWord)
searchIn
for an occurrence of regEx
either forwards or backwards, matching case or not.regEx
- The regular expression to look for.searchIn
- The string to search in.goForward
- Whether to search forward. If false
,
search backward.matchCase
- Whether or not to do a case-sensitive search for
regEx
.wholeWord
- If true
, regEx
occurrences embedded in longer words in searchIn
don't count as matches.Point
representing the starting and ending
position of the match, or null
if no match was
found.PatternSyntaxException
- If regEx
is an invalid
regular expression.getNextMatchPos(java.lang.String, java.lang.String, boolean, boolean, boolean)
protected static Object getNextMatchPosRegExImpl(String regEx, CharSequence searchIn, boolean goForward, boolean matchCase, boolean wholeWord, String replaceStr)
searchIn
for an occurrence of regEx
either forwards or backwards, matching case or not.regEx
- The regular expression to look for.searchIn
- The string to search in.goForward
- Whether to search forward. If false
,
search backward.matchCase
- Whether or not to do a case-sensitive search for
regEx
.wholeWord
- If true
, regEx
occurrences embedded in longer words in searchIn
don't count as matches.replaceStr
- The string that will replace the match found (if
a match is found). The object returned will contain the
replacement string with matched groups substituted. If this
value is null
, it is assumed this call is part of a
"find" instead of a "replace" operation.replaceStr
is null
, a
Point
representing the starting and ending points
of the match. If it is non-null
, an object with
information about the match and the morphed string to replace
it with. If no match is found, null
is returned.PatternSyntaxException
- If regEx
is an invalid
regular expression.IndexOutOfBoundsException
- If replaceStr
references
an invalid group (less than zero or greater than the number of
groups matched).getNextMatchPos(java.lang.String, java.lang.String, boolean, boolean, boolean)
protected static org.fife.ui.rtextarea.RegExReplaceInfo getRegExReplaceInfo(String regEx, String searchIn, boolean goForward, boolean matchCase, boolean wholeWord, String replacement)
regEx
- The regular expression to look for.searchIn
- The string to search in.goForward
- Whether to search forward. If false
,
search backward.matchCase
- Whether or not to do a case-sensitive search for
regEx
.wholeWord
- If true
, regEx
occurrences
embedded in longer words in searchIn
don't count as
matches.replacement
- A template for the replacement string (e.g., this
can contain \t
and \n
to mean tabs
and newlines, respectively, as well as group references
$n
).RegExReplaceInfo
object describing how to
implement the replace.PatternSyntaxException
- If regEx
is an invalid
regular expression.IndexOutOfBoundsException
- If replacement
references
an invalid group (less than zero or greater than the number of
groups matched).getNextMatchPos(java.lang.String, java.lang.String, boolean, boolean, boolean)
public static String getReplacementText(Matcher m, CharSequence template)
getMatches()
. This method assumes
that the specified matcher has just found a match, and that you want
to get the string with which to replace that match.m
- The matcher.template
- The template for the replacement string. For example,
"foo
" would yield the replacement string
"foo
", while "$1 is the greatest
"
would yield different values depending on the value of the first
captured group in the match.IndexOutOfBoundsException
- If template
references
an invalid group (less than zero or greater than the number of
groups matched).protected static int makeMarkAndDotEqual(JTextArea textArea, boolean forward)
textArea
- The text area.forward
- Whether the search will be forward through the
document (false
means backward).protected static boolean regexReplace(JTextArea textArea, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord) throws PatternSyntaxException
textArea
- The text area in which to search.toFind
- The regular expression to search for.replaceWith
- The string to replace the found regex with.forward
- Whether to search forward from the caret position
or backward from it.matchCase
- Whether the search should be case-sensitive.wholeWord
- Whether there should be spaces or tabs on either
side of the match.PatternSyntaxException
- If toFind
is not a
valid regular expression.IndexOutOfBoundsException
- If replaceWith
references
an invalid group (less than zero or greater than the number of
groups matched).replace(org.fife.ui.rtextarea.RTextArea, java.lang.String, java.lang.String, boolean, boolean, boolean, boolean)
,
find(javax.swing.JTextArea, java.lang.String, boolean, boolean, boolean, boolean)
public static boolean replace(RTextArea textArea, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord, boolean regex) throws PatternSyntaxException
textArea
- The text area in which to search.toFind
- The text/regular expression to search for.replaceWith
- The string to replace the found text with.forward
- Whether to search forward from the caret position or
backward from it.matchCase
- Whether the search should be case-sensitive.wholeWord
- Whether there should be spaces or tabs on either
side of the match.regex
- Whether or not this is a regular expression search.PatternSyntaxException
- If regex
is
true
but toFind
is not a valid
regular expression.IndexOutOfBoundsException
- If regex
is
true
and replaceWith
references
an invalid group (less than zero or greater than the number
of groups matched).regexReplace(javax.swing.JTextArea, java.lang.String, java.lang.String, boolean, boolean, boolean)
,
find(javax.swing.JTextArea, java.lang.String, boolean, boolean, boolean, boolean)
public static int replaceAll(RTextArea textArea, String toFind, String replaceWith, boolean matchCase, boolean wholeWord, boolean regex) throws PatternSyntaxException
textArea
- The text area in which to search.toFind
- The text/regular expression to search for.replaceWith
- The string to replace the found text with.matchCase
- Whether the search should be case-sensitive.wholeWord
- Whether there should be spaces or tabs on either
side of the match.regex
- Whether or not this is a regular expression search.PatternSyntaxException
- If regex
is
true
and toFind
is an invalid
regular expression.IndexOutOfBoundsException
- If replaceWith
references
an invalid group (less than zero or greater than the number of
groups matched).replace(org.fife.ui.rtextarea.RTextArea, java.lang.String, java.lang.String, boolean, boolean, boolean, boolean)
,
regexReplace(javax.swing.JTextArea, java.lang.String, java.lang.String, boolean, boolean, boolean)
,
find(javax.swing.JTextArea, java.lang.String, boolean, boolean, boolean, boolean)