}
end += Character.charCount(contents.codePointAt(end));
}
// Report error
CheckErrorResult errorResult = createCheckErrorResult(analysis, begin, end);
for (Integer controlFound : controls) {
ControlCharacter found = getControlCharacter(controlFound.intValue());
if (found != null) {
errorResult.addPossibleAction(
Integer.toHexString(controlFound.intValue()) + " - " + GT._(found.description),
new NullActionProvider());
}
}
StringBuilder replacementB = new StringBuilder();
List<String> otherReplacements = new ArrayList<String>();
boolean unsafeCharacter = false;
boolean checkUnsafe = false;
int i = begin;
while (i < end) {
codePoint = contents.codePointAt(i);
control = getControlCharacter(codePoint);
if (control == null) {
replacementB.appendCodePoint(codePoint);
unsafeCharacter = (automaticChars.indexOf(codePoint) < 0);
} else {
if (!control.removable) {
int replaceBy = 0;
if (control == ControlCharacter.NON_BREAKING_SPACE) {
if ((i > 0) && (contents.codePointBefore(i) == '«')) {
replaceBy = ' ';
}
int next = i + Character.charCount(codePoint);
if (next < end) {
int codePointAfter = contents.codePointAt(next);
if ((codePointAfter == '»') || (codePointAfter == ':')) {
replaceBy = ' ';
}
}
}
if (replaceBy == 0) {
replacementB.appendCodePoint(codePoint);
checkUnsafe = true;
} else {
replacementB.appendCodePoint(replaceBy);
}
}
checkUnsafe |= !control.safe;
List<String> replacements = ControlCharacter.getReplacements(codePoint);
if (replacements != null) {
for (String replacement : replacements) {
StringBuilder otherReplacement = new StringBuilder();
int j = begin;
while (j < end) {
int codePointJ = contents.codePointAt(j);
if ((i != j) && (codePoint != codePointJ)) {
otherReplacement.appendCodePoint(codePointJ);
} else {
otherReplacement.append(replacement);
}
j += Character.charCount(codePointJ);
}
if (!otherReplacements.contains(otherReplacement.toString())) {
otherReplacements.add(otherReplacement.toString());
}
}
}
}
i += Character.charCount(codePoint);
}
boolean automatic = !unsafeCharacter || !checkUnsafe;
String original = contents.substring(begin, end);
String replacement = replacementB.toString();
if (!replacement.equals(original)) {
errorResult.addReplacement(
replacement,
GT._("Remove all control characters"),
automatic);
}
for (String otherReplacement : otherReplacements) {
if ((!automatic || replacement.equals(original)) &&
!otherReplacement.equals(original) &&
!otherReplacement.equals(replacement)) {
errorResult.addReplacement(otherReplacement);
}
}
errors.add(errorResult);
index = end;
} else {