Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import com.google.common.escape.Escapers;

public class MetacharEscaper extends Escaper {
private static final MetacharEscaper SINGLETON = new MetacharEscaper();

// Handle escape characters (https://docs.oracle.com/javase/tutorial/java/data/characters.html)
// for the comments here, else JavaFormmater cannot properly format the string comment.
// `"` and `'` are overlooked because the comments will not be surrounded by `"` or `'`.
private static final Escaper escaper =
private static final Escaper charEscaper =
Escapers.builder()
.addEscape('\t', "\\t")
.addEscape('\b', "\\b")
Expand All @@ -35,10 +37,10 @@ private MetacharEscaper() {}

@Override
public String escape(String sourceString) {
return escaper.escape(sourceString);
return charEscaper.escape(sourceString);
}

public static String escaper(String source) {
return new MetacharEscaper().escape(source);
return SINGLETON.escape(source);
}
}