Iterator<Suggestion> itSuggestion = suggestions.iterator();
List<Replacement> tmpReplacements = new ArrayList<CheckErrorAlgorithm501.Replacement>();
while (itSuggestion.hasNext()) {
Suggestion suggestion = itSuggestion.next();
if (!suggestion.isOtherPattern()) {
Performance perf = new Performance("Slow regular expression");
perf.setThreshold(slowRegexp);
itSuggestion.remove();
Matcher matcher = suggestion.initMatcher(contents);
for (ContentsChunk chunk : chunks) {
matcher.region(chunk.getBegin(), chunk.getEnd());
int authorizedBegin = chunk.getBegin();
while (matcher.find()) {
int begin = matcher.start();
int end = matcher.end();
boolean shouldKeep = true;
if (shouldKeep && (begin > 0) &&
(Character.isLetterOrDigit(contents.charAt(begin))) &&
(Character.isLetterOrDigit(contents.charAt(begin - 1)))) {
shouldKeep = false;
}
if (shouldKeep && (end < contents.length()) &&
(Character.isLetterOrDigit(contents.charAt(end))) &&
(Character.isLetterOrDigit(contents.charAt(end - 1)))) {
shouldKeep = false;
}
if (shouldKeep) {
tmpReplacements.clear();
shouldKeep = addReplacements(
begin, end, contents, authorizedBegin, chunk.getEnd(),
suggestion, tmpReplacements);
}
if (shouldKeep && (analysis.getAreas().getEndArea(begin) > begin)) {
shouldKeep = false;
}
if (shouldKeep && (analysis.isInTemplate(begin) != null)) {
shouldKeep = false;
}
if (shouldKeep) {
shouldKeep = shouldKeep(contents, begin, end);
}
if (shouldKeep) {
result = true;
replacements.addAll(tmpReplacements);
}
authorizedBegin = end;
}
}
perf.printEnd(suggestion.getPatternText());
}
}
return result;
}