public class SimpleStringEscaper extends Object implements StringEscaper
Provides simple escaping and unescaping for 8-bit strings. The resulting string should survive translation between common line-ending conventions.
Escapes ASCII '\', '\n', '\r' by replacing them with literals "\\", "\\n", "\\r" respectively. Adds a new line ('\n') after replacing a '\n' so the resulting text is reasonably formatted. The unescape method strips all '\n' and '\r' in the input. Ignores platform line endings, that's only an issue for whatever does I/O with the results.
Class invariant: for all strings S, S=unescape(escape(S))
.
However, it is not true that
for all Strings S, S=escape(unescape(S))
because unescape(S)
strips {'\n', '\r'}.
public String escape(String unencoded)
escape
in interface StringEscaper
unencoded
- The original string.public String unescape(String encoded)
unescape
in interface StringEscaper
encoded
- The escaped string.Copyright © 2000-2014. All Rights Reserved.