-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84bd780
commit b0f187a
Showing
2 changed files
with
0 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,54 +122,4 @@ private String printPossibleComment(final YamlNode node) { | |
} | ||
return wrtr.toString(); | ||
} | ||
|
||
/** | ||
* A scalar which escapes its value. | ||
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 4.3.1 | ||
* @checkstyle LineLength (100 lines) | ||
*/ | ||
static class Escaped extends BaseScalar { | ||
|
||
/** | ||
* Original unescaped scalar. | ||
*/ | ||
private final Scalar original; | ||
|
||
/** | ||
* Ctor. | ||
* @param original Unescaped scalar. | ||
*/ | ||
Escaped(final Scalar original) { | ||
this.original = original; | ||
} | ||
|
||
@Override | ||
public String value() { | ||
final String value = this.original.value(); | ||
String toEscape; | ||
if(value == null) { | ||
toEscape = "null"; | ||
} else { | ||
toEscape = value; | ||
} | ||
boolean alreadyEscaped = (toEscape.startsWith("'") && toEscape.endsWith("'")) | ||
|| (toEscape.startsWith("\"") && toEscape.endsWith("\"")); | ||
final String needsEscaping = ".*[?\\-#:>|$%&{}\\[\\]@`!*,'\"]+.*|[ ]+|null"; | ||
if (!alreadyEscaped && toEscape.matches(needsEscaping)) { | ||
if(toEscape.contains("\"")) { | ||
toEscape = "'" + toEscape + "'"; | ||
} else { | ||
toEscape = "\"" + toEscape + "\""; | ||
} | ||
} | ||
return toEscape; | ||
} | ||
|
||
@Override | ||
public Comment comment() { | ||
return this.original.comment(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters