Rather than creating multiple matchers for no good reason at all,
check if the string contains a backslash character before going
in and performing escaping.
JIRA: YANGTOOLS-652
Change-Id: I77fb02bad4ffb13a8393956c56b15ebe3e1dbf3f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
* in the inner string and trim the result.
*/
checkDoubleQuotedString(innerStr, yangVersion, ref);
* in the inner string and trim the result.
*/
checkDoubleQuotedString(innerStr, yangVersion, ref);
-
- sb.append(ESCAPED_TAB.matcher(
- ESCAPED_LF.matcher(
- ESCAPED_BACKSLASH.matcher(
- ESCAPED_DQUOT.matcher(
- trimWhitespace(innerStr, stringNode.getSymbol().getCharPositionInLine()))
- .replaceAll("\\\""))
- .replaceAll("\\\\"))
- .replaceAll("\\\n"))
- .replaceAll("\\\t"));
+ sb.append(unescape(trimWhitespace(innerStr, stringNode.getSymbol().getCharPositionInLine())));
} else if (firstChar == '\'' && lastChar == '\'') {
/*
* According to RFC6020 a single quote character cannot occur in
} else if (firstChar == '\'' && lastChar == '\'') {
/*
* According to RFC6020 a single quote character cannot occur in
+ private static String unescape(final String str) {
+ final int backslash = str.indexOf('\\');
+ if (backslash == -1) {
+ return str;
+ }
+
+ // FIXME: given we the leading backslash, it would be more efficient to walk the string and unescape in one go
+ return ESCAPED_TAB.matcher(
+ ESCAPED_LF.matcher(
+ ESCAPED_BACKSLASH.matcher(
+ ESCAPED_DQUOT.matcher(str).replaceAll("\\\""))
+ .replaceAll("\\\\"))
+ .replaceAll("\\\n"))
+ .replaceAll("\\\t");
+ }
+
private static void checkUnquotedString(final String str, final YangVersion yangVersion,
final StatementSourceReference ref) {
if (yangVersion == YangVersion.VERSION_1_1) {
private static void checkUnquotedString(final String str, final YangVersion yangVersion,
final StatementSourceReference ref) {
if (yangVersion == YangVersion.VERSION_1_1) {