try {
replaceText= interpretReplaceEscapes(replaceText, prevMatch);
Matcher replaceTextMatcher= pattern.matcher(prevMatch);
replaceText= replaceTextMatcher.replaceFirst(replaceText);
} catch (IndexOutOfBoundsException ex) {
throw new PatternSyntaxException(ex.getLocalizedMessage(), replaceText, -1);
}
}
int offset= fFindReplaceMatcher.start();
int length= fFindReplaceMatcher.group().length();
if (fDocument instanceof IRepairableDocumentExtension
&& ((IRepairableDocumentExtension)fDocument).isLineInformationRepairNeeded(offset, length, replaceText)) {
String message= TextMessages.getString("FindReplaceDocumentAdapter.incompatibleLineDelimiter"); //$NON-NLS-1$
throw new PatternSyntaxException(message, replaceText, offset);
}
fDocument.replace(offset, length, replaceText);
if (operationCode == REPLACE) {
return new Region(offset, replaceText.length());
}
}
if (operationCode != REPLACE) {
try {
if (forwardSearch) {
boolean found= false;
if (operationCode == FIND_FIRST)
found= fFindReplaceMatcher.find(startOffset);
else
found= fFindReplaceMatcher.find();
if (operationCode == REPLACE_FIND_NEXT)
fFindReplaceState= FIND_NEXT;
if (found && fFindReplaceMatcher.group().length() > 0)
return new Region(fFindReplaceMatcher.start(), fFindReplaceMatcher.group().length());
return null;
}
// backward search
boolean found= fFindReplaceMatcher.find(0);
int index= -1;
int length= -1;
while (found && fFindReplaceMatcher.start() + fFindReplaceMatcher.group().length() <= fFindReplaceMatchOffset + 1) {
index= fFindReplaceMatcher.start();
length= fFindReplaceMatcher.group().length();
found= fFindReplaceMatcher.find(index + 1);
}
fFindReplaceMatchOffset= index;
if (index > -1) {
// must set matcher to correct position
fFindReplaceMatcher.find(index);
return new Region(index, length);
}
return null;
} catch (StackOverflowError e) {
String message= TextMessages.getString("FindReplaceDocumentAdapter.patternTooComplex"); //$NON-NLS-1$
throw new PatternSyntaxException(message, findString, -1);
}
}
return null;
}