introduce hasNo() methods in Constant to improve readability
diff --git a/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java b/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
index 2513f21..4de88ae 100644
--- a/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
+++ b/src/main/java/org/yaml/snakeyaml/emitter/Emitter.java
@@ -1148,7 +1148,7 @@
start = end;
}
} else if (breaks) {
- if (ch == 0 || !Constant.LINEBR.has(ch)) {
+ if (ch == 0 || Constant.LINEBR.hasNo(ch)) {
if (text.charAt(start) == '\n') {
writeLineBreak(null);
}
@@ -1255,7 +1255,7 @@
hints.append(bestIndent);
}
char ch1 = text.charAt(text.length() - 1);
- if (!Constant.LINEBR.has(ch1)) {
+ if (Constant.LINEBR.hasNo(ch1)) {
hints.append("-");
} else if (text.length() == 1 || Constant.LINEBR.has(text.charAt(text.length() - 2))) {
hints.append("+");
@@ -1281,7 +1281,7 @@
ch = text.charAt(end);
}
if (breaks) {
- if (ch == 0 || !Constant.LINEBR.has(ch)) {
+ if (ch == 0 || Constant.LINEBR.hasNo(ch)) {
if (!leadingSpace && ch != 0 && ch != ' ' && text.charAt(start) == '\n') {
writeLineBreak(null);
}
@@ -1344,7 +1344,7 @@
ch = text.charAt(end);
}
if (breaks) {
- if (ch == 0 || !Constant.LINEBR.has(ch)) {
+ if (ch == 0 || Constant.LINEBR.hasNo(ch)) {
String data = text.substring(start, end);
for (char br : data.toCharArray()) {
if (br == '\n') {
@@ -1411,7 +1411,7 @@
start = end;
}
} else if (breaks) {
- if (!Constant.LINEBR.has(ch)) {
+ if (Constant.LINEBR.hasNo(ch)) {
if (text.charAt(start) == '\n') {
writeLineBreak(null);
}
diff --git a/src/main/java/org/yaml/snakeyaml/scanner/Constant.java b/src/main/java/org/yaml/snakeyaml/scanner/Constant.java
index 2067bd2..9577e7f 100644
--- a/src/main/java/org/yaml/snakeyaml/scanner/Constant.java
+++ b/src/main/java/org/yaml/snakeyaml/scanner/Constant.java
@@ -39,7 +39,15 @@
return content.indexOf(ch) != -1;
}
+ public boolean hasNo(char ch) {
+ return !has(ch);
+ }
+
public boolean has(String additional, char ch) {
return additional.indexOf(ch) != -1 || content.indexOf(ch) != -1;
}
+
+ public boolean hasNo(String additional, char ch) {
+ return !has(additional, ch);
+ }
}
diff --git a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
index 24023a7..1ecdf44 100644
--- a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
+++ b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
@@ -939,8 +939,8 @@
* </pre>
*/
char ch = reader.peek();
- return (!Constant.NULL_BL_T_LINEBR.has("-?:,[]{}#&*!|>\'\"%@`", ch) || !Constant.NULL_BL_T_LINEBR
- .has(reader.peek(1))
+ return (Constant.NULL_BL_T_LINEBR.hasNo("-?:,[]{}#&*!|>\'\"%@`", ch) || Constant.NULL_BL_T_LINEBR
+ .hasNo(reader.peek(1))
&& (ch == '-' || (this.flowLevel == 0 && "?:".indexOf(ch) != -1)));
}
@@ -977,7 +977,7 @@
reader.forward();
}
if (reader.peek() == '#') {
- while (!Constant.NULL_OR_LINEBR.has(reader.peek())) {
+ while (Constant.NULL_OR_LINEBR.hasNo(reader.peek())) {
reader.forward();
}
}
@@ -1006,7 +1006,7 @@
endMark = reader.getMark();
} else {
endMark = reader.getMark();
- while (!Constant.NULL_OR_LINEBR.has(reader.peek())) {
+ while (Constant.NULL_OR_LINEBR.hasNo(reader.peek())) {
reader.forward();
}
}
@@ -1030,7 +1030,7 @@
String value = reader.prefix(length);
reader.forward(length);
ch = reader.peek();
- if (!Constant.NULL_BL_LINEBR.has(ch)) {
+ if (Constant.NULL_BL_LINEBR.hasNo(ch)) {
throw new ScannerException("while scanning a directive", startMark,
"expected alphabetic or numeric character, but found " + ch + "(" + ((int) ch)
+ ")", reader.getMark());
@@ -1051,7 +1051,7 @@
}
reader.forward();
Integer minor = scanYamlDirectiveNumber(startMark);
- if (!Constant.NULL_BL_LINEBR.has(reader.peek())) {
+ if (Constant.NULL_BL_LINEBR.hasNo(reader.peek())) {
throw new ScannerException("while scanning a directive", startMark,
"expected a digit or ' ', but found " + reader.peek() + "("
+ ((int) reader.peek()) + ")", reader.getMark());
@@ -1108,7 +1108,7 @@
private String scanTagDirectivePrefix(Mark startMark) {
// See the specification for details.
String value = scanTagUri("directive", startMark);
- if (!Constant.NULL_BL_LINEBR.has(reader.peek())) {
+ if (Constant.NULL_BL_LINEBR.hasNo(reader.peek())) {
throw new ScannerException("while scanning a directive", startMark,
"expected ' ', but found " + reader.peek() + "(" + ((int) reader.peek()) + ")",
reader.getMark());
@@ -1122,12 +1122,12 @@
reader.forward();
}
if (reader.peek() == '#') {
- while (!Constant.NULL_OR_LINEBR.has(reader.peek())) {
+ while (Constant.NULL_OR_LINEBR.hasNo(reader.peek())) {
reader.forward();
}
}
char ch = reader.peek();
- if (!Constant.NULL_OR_LINEBR.has(ch)) {
+ if (Constant.NULL_OR_LINEBR.hasNo(ch)) {
throw new ScannerException("while scanning a directive", startMark,
"expected a comment or a line break, but found " + ch + "(" + ((int) ch) + ")",
reader.getMark());
@@ -1166,7 +1166,7 @@
String value = reader.prefix(length);
reader.forward(length);
ch = reader.peek();
- if (!Constant.NULL_BL_T_LINEBR.has("?:,]}%@`", ch)) {
+ if (Constant.NULL_BL_T_LINEBR.hasNo("?:,]}%@`", ch)) {
throw new ScannerException("while scanning an " + name, startMark,
"expected alphabetic or numeric character, but found " + ch + "("
+ ((int) reader.peek()) + ")", reader.getMark());
@@ -1202,7 +1202,7 @@
} else {
int length = 1;
boolean useHandle = false;
- while (!Constant.NULL_BL_LINEBR.has(ch)) {
+ while (Constant.NULL_BL_LINEBR.hasNo(ch)) {
if (ch == '!') {
useHandle = true;
break;
@@ -1220,7 +1220,7 @@
suffix = scanTagUri("tag", startMark);
}
ch = reader.peek();
- if (!Constant.NULL_BL_LINEBR.has(ch)) {
+ if (Constant.NULL_BL_LINEBR.hasNo(ch)) {
throw new ScannerException("while scanning a tag", startMark,
"expected ' ', but found '" + ch + "' (" + ((int) ch) + ")", reader.getMark());
}
@@ -1275,7 +1275,7 @@
chunks.append(breaks);
boolean leadingNonSpace = " \t".indexOf(reader.peek()) == -1;
int length = 0;
- while (!Constant.NULL_OR_LINEBR.has(reader.peek(length))) {
+ while (Constant.NULL_OR_LINEBR.hasNo(reader.peek(length))) {
length++;
}
chunks.append(reader.prefix(length));
@@ -1355,7 +1355,7 @@
}
}
ch = reader.peek();
- if (!Constant.NULL_BL_LINEBR.has(ch)) {
+ if (Constant.NULL_BL_LINEBR.hasNo(ch)) {
throw new ScannerException("while scanning a block scalar", startMark,
"expected chomping or indentation indicators, but found " + ch, reader
.getMark());
@@ -1369,12 +1369,12 @@
reader.forward();
}
if (reader.peek() == '#') {
- while (!Constant.NULL_OR_LINEBR.has(reader.peek())) {
+ while (Constant.NULL_OR_LINEBR.hasNo(reader.peek())) {
reader.forward();
}
}
char ch = reader.peek();
- if (!Constant.NULL_OR_LINEBR.has(ch)) {
+ if (Constant.NULL_OR_LINEBR.hasNo(ch)) {
throw new ScannerException("while scanning a block scalar", startMark,
"expected a comment or a line break, but found " + ch, reader.getMark());
}
@@ -1453,7 +1453,7 @@
StringBuilder chunks = new StringBuilder();
while (true) {
int length = 0;
- while (!Constant.NULL_BL_T_LINEBR.has("\'\"\\", reader.peek(length))) {
+ while (Constant.NULL_BL_T_LINEBR.hasNo("\'\"\\", reader.peek(length))) {
length++;
}
if (length != 0) {
@@ -1584,7 +1584,7 @@
}
// It's not clear what we should do with ':' in the flow context.
if (this.flowLevel != 0 && ch == ':'
- && !Constant.NULL_BL_T_LINEBR.has(",[]{}", reader.peek(length + 1))) {
+ && Constant.NULL_BL_T_LINEBR.hasNo(",[]{}", reader.peek(length + 1))) {
reader.forward(length);
throw new ScannerException("while scanning a plain scalar", startMark,
"found unexpected ':'", reader.getMark(),