IG: don't report (more) invisible characters as unnecessary escapes (IDEA-169813)

This commit is contained in:
Bas Leijdekkers
2017-03-18 09:05:48 +01:00
parent 401a5af85d
commit c9bfa67992
2 changed files with 18 additions and 2 deletions
@@ -37,7 +37,10 @@ import org.jetbrains.annotations.Nullable;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.*;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
/**
* @author Bas Leijdekkers
@@ -146,7 +149,17 @@ public class UnnecessaryUnicodeEscapeInspection extends BaseInspection {
StringUtil.isHexDigit(text.charAt(nextChar + 3))) {
final int escapeEnd = nextChar + 4;
final char d = (char)Integer.parseInt(text.substring(nextChar, escapeEnd), 16);
if (Character.isISOControl(d)) {
final int type = Character.getType(d);
if (type == Character.CONTROL ||
type == Character.FORMAT ||
type == Character.PRIVATE_USE ||
type == Character.SURROGATE ||
type == Character.UNASSIGNED ||
type == Character.LINE_SEPARATOR ||
type == Character.PARAGRAPH_SEPARATOR) {
continue;
}
if (type == Character.SPACE_SEPARATOR && d != ' ') {
continue;
}
byteBuffer.clear();
@@ -5,6 +5,9 @@ class UnnecessaryUnicodeEscape {
// control char & not representable char: \u0010 \u00e4
char[] surrogates = new char[]{'\ud800','\udc00'};
String t = "<warning descr="Unicode escape sequence '\u0020' can be replaced with ' '">\u0020</warning>";
String u = "\u200B\u200E\u00A0\u200F";
}
@SuppressWarnings("UnnecessaryUnicodeEscape")
class Suppress {