+ private void appendString(final StringBuilder sb, final TerminalNode stringNode,
+ final StatementSourceReference ref) {
+
+ final String str = stringNode.getText();
+ final char firstChar = str.charAt(0);
+ final char lastChar = str.charAt(str.length() - 1);
+ // NOTE: Enforcement and transformation logic here should certainly be pushed down to the lexer, as ANTLR can
+ // account the for it with lexer modes. One problem is that lexing here depends on version being lexed,
+ // hence we really would have to re-parse the YANG file after determining its version. We certainly do not
+ // want to do that.
+ // FIXME: YANGTOOLS-1079: but since we are performing quoting checks, perhaps at least that part could be lexed?
+ if (firstChar == '"' && lastChar == '"') {
+ final String innerStr = str.substring(1, str.length() - 1);
+ /*
+ * Unescape escaped double quotes, tabs, new line and backslash
+ * in the inner string and trim the result.
+ */
+ checkDoubleQuotedString(innerStr, ref);
+ sb.append(unescape(trimWhitespace(innerStr, stringNode.getSymbol().getCharPositionInLine())));
+ } else if (firstChar == '\'' && lastChar == '\'') {
+ /*
+ * According to RFC6020 a single quote character cannot occur in
+ * a single-quoted string, even when preceded by a backslash.
+ */
+ sb.append(str, 1, str.length() - 1);
+ } else {
+ checkUnquotedString(str, ref);
+ sb.append(str);
+ }
+ }
+
+ abstract void checkDoubleQuotedString(String str, StatementSourceReference ref);
+
+ abstract void checkUnquotedString(String str, StatementSourceReference ref);
+