提交 d1516da3 authored 作者: Thomas Mueller's avatar Thomas Mueller

Trailing whitespace is now automatically truncated

上级 b51492c1
...@@ -149,6 +149,7 @@ public class CheckTextFiles { ...@@ -149,6 +149,7 @@ public class CheckTextFiles {
boolean lastWasWhitespace = false; boolean lastWasWhitespace = false;
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
char ch = (char) (data[i] & 0xff); char ch = (char) (data[i] & 0xff);
boolean isWhitespace = Character.isWhitespace(ch);
if (ch > 127) { if (ch > 127) {
fail(file, "contains character " + (int) ch + " at " + new String(data, i - 10, 20), line); fail(file, "contains character " + (int) ch + " at " + new String(data, i - 10, 20), line);
return; return;
...@@ -194,11 +195,31 @@ public class CheckTextFiles { ...@@ -194,11 +195,31 @@ public class CheckTextFiles {
fail(file, "contains character " + (int) ch, line); fail(file, "contains character " + (int) ch, line);
return; return;
} }
} else if (isWhitespace) {
lastWasWhitespace = true;
if (fix) {
boolean write = true;
for (int j = i + 1; j < data.length; j++) {
char ch2 = (char) (data[j] & 0xff);
if (ch2 == '\n' || ch2 == '\r') {
write = false;
lastWasWhitespace = false;
ch = ch2;
i = j - 1;
break;
} else if (!Character.isWhitespace(ch2)) {
break;
}
}
if (write) {
out.write(ch);
}
}
} else { } else {
if (fix) { if (fix) {
out.write(ch); out.write(ch);
} }
lastWasWhitespace = Character.isWhitespace(ch); lastWasWhitespace = false;
} }
} }
if (lastWasWhitespace && !allowTrailingSpaces) { if (lastWasWhitespace && !allowTrailingSpaces) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论